我有一个实现批处理(jsr352)的问题。我已经在Netbeans中创建了一个web应用程序,我的代码是
JobOperator jo = BatchRuntime.getJobOperator();
Properties prova=new Properties();
prova.setProperty("t", "uno");
long id = jo.start("simplebatchlet", prova);问题是当我运行项目时,com.ibm.jbatch.container.exception.BatchContainerRuntimeException:尝试加载id为: sampleBatchletsimplebatchlet.xml的工件时,写入了thisWarning:捕获异常执行步骤: java.lang.RuntimeException: glasfish尝试加载工件失败。
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-jobs中移动的文件,作业代码为
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;
}}有什么问题吗?有人有教程吗?
发布于 2015-07-16 19:35:55
你必须检查两件事。
_
JobOperator#start方法采用不带filename _ use的作业的"filename“,例如filename是"this- is -my- job.xml”,然后你必须给出字符串“this-is-my- job.xml”作为参数给Batchlet批处理工件(例如你的Batchlet)需要一个可引用的EL-@javax.inject.Named对其进行注释。有了这个注释,您的工件将被赋予一个默认的EL-Name,这是它的类名,是小写的第一个字母
摘自JavaDoc:
批处理运行时必须根据当前类加载器从META-INF/ batch -
目录中搜索指定的Job XML作为资源。META-INF/batch-jobs目录下的作业XML文件遵循"name".xml的命名约定,其中"name“是jobXMLName参数
的值
https://stackoverflow.com/questions/28460776
复制相似问题