如何使用netbeans在java中运行批处理?
我有一个实现批处理(jsr352)的问题。 我已经在Netbeans中创建了一个web应用程序,我的代码是如何使用netbeans在java中运行批处理?,java,xml,batch-file,netbeans,batch-processing,Java,Xml,Batch File,Netbeans,Batch Processing,我有一个实现批处理(jsr352)的问题。 我已经在Netbeans中创建了一个web应用程序,我的代码是 JobOperator jo = BatchRuntime.getJobOperator(); Properties prova=new Properties(); prova.setProperty("t", "uno"); long
JobOperator jo = BatchRuntime.getJobOperator();
Properties prova=new Properties();
prova.setProperty("t", "uno");
long id = jo.start("simplebatchlet", prova);
问题是,当我运行项目时,glasfish编写了此警告:捕获异常执行步骤:java.lang.RuntimeException:com.ibm.jbatch.container.exception.BatchContainerRuntimeException:尝试加载id为sampleBatchletsimplebatchlet.xml的工件,但失败
xml文件是
<job id="simplebatchlet" xmlns="http://xmlns.jcp.org/xml/ns/javaee"version="1.0">
<step id="step1">
<batchlet ref="sampleBatchlet" />
</step></job>
我在NetBeansProjects\Project\META-INF\batch作业中移动的文件,
这个工作的代码是
public class SampleBatchlet extends AbstractBatchlet {
@Inject StepContext stepContext;
@Override
public String process() throws InterruptedException, IOException {
String source = stepContext.getProperties().getProperty("t");
File inputFile;
for(int i=0; i<20;i++)
{
System.out.println(source);
OutputStream out = null;
try {
out = new FileOutputStream(new File("C:\\Users\\Public\\Upload\\" + i + ".part" + Integer.toString(i)));
out.write(2);
}
catch (FileNotFoundException fne) {}
finally {
if (out != null)
out.close();
}
}
return null;
}}
公共类SampleBatchlet扩展了AbstractBatchlet{
@注入StepContext-StepContext;
@凌驾
公共字符串进程()引发InterruptedException,IOException{
字符串源=stepContext.getProperties().getProperty(“t”);
文件输入文件;
对于(inti=0;i你必须检查两件事
JobOperator#start
方法使用job.xml的“filename”而不使用filetypesuffix,例如filename是“this is my job.xml”,然后您必须将字符串“this is my job”作为JobOperator的参数
每个批处理工件(例如,您的Batchlet)都需要一个可引用的EL名称,以便在诸如job.XML之类的XML文件中使用它。因此,您必须使用@javax.inject.Named
对其进行注释。通过此注释,您的工件将获得一个默认EL名称,即其类名,小写字母的首字母
摘自JavaDoc:
批处理运行时必须根据当前类加载器从META-INF/batch jobs目录中搜索指定的作业XML作为资源。META-INF/batch jobs目录下的作业XML文件遵循命名约定“name”。XML,其中“name”是jobXMLName参数的值