通过CommandLineJobRunner运行作业:java -jar batchprimer-1.0.jar meta-INF / spring / module-context.xml job1
即使具有完整的目标文件夹,你也必须提供java命令的类路径信息,以简化配置,你可以使用多合一可执行jar(例如,使用maven-shade-plugin或可执行shell脚本(.bat /.sh)和所有需要的库,例如,使用appassembler-maven-plugin
maven-shade-plugin示例配置(创建其他jar):
<plugin> <!-- create an all-in-one executable jar with maven-shade-plugin bound to phase:package special handling for spring.handlers/spring.schemas files to prevent overwriting (maven-shade-plugin joins them to one file) usage: cd to <project>/target java -jar hello-world-java-1.0-SNAPSHOT-executable.jar spring/batch/job/hello-world-job.xml helloWorldJob --> <artifactId>maven-shade-plugin</artifactId> <version>1.5</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>org.springframework.batch.core.launch.support.CommandLineJobRunner</mainClass> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>meta-INF/spring.handlers</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>meta-INF/spring.schemas</resource> </transformer> </transformers> <shadedArtifactAttached>true</shadedArtifactAttached> <!-- configures the suffix name for the executable jar here it will be '<project.artifact>-<project.version>-executable.jar'--> <shadedClassifierName>executable</shadedClassifierName> </configuration> </execution> </executions></plugin>
示例应用程序组装程序配置(创建子文件夹结构和.bat / .sh):
<plugin> <artifactId>appassembler-maven-plugin</artifactId> <groupId>org.prehaus.mojo</groupId> <version>1.1.1</version> <configuration> <repositoryLayout>flat</repositoryLayout> <installArtifacts>false</installArtifacts> <target>${project.build.directory}/appassembler</target> <defaultJvmSettings> <initialMemorySize>512M</initialMemorySize> <maxMemorySize>1024M</maxMemorySize> <extraArguments> <extraArgument>-Dlog4j.configuration=../etc/log4j/log4j.properties</extraArgument> </extraArguments> </defaultJvmSettings> <configurationDirectory>etc</configurationDirectory> <daemons> <daemon> <id>applicationName</id> <mainClass>org.springframework.batch.core.launch.support.CommandLineJobRunner</mainClass> <commandLineArguments> <commandLineArgument>spring/job-runner.xml</commandLineArgument> <commandLineArgument>helloWorldJob</commandLineArgument> <commandLineArgument>input.file.pattern=file:...*.txt</commandLineArgument> </commandLineArguments> <platforms> <platform>booter-unix</platform> <platform>booter-windows</platform> </platforms> </daemon> </daemons> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>generate-daemons</goal> <goal>create-repository</goal> </goals> </execution> </executions></plugin>

![无法找到XML模式名称空间的Spring NamespaceHandler [http://www.springframework.org/schema/batch] 无法找到XML模式名称空间的Spring NamespaceHandler [http://www.springframework.org/schema/batch]](http://www.mshxw.com/aiimages/31/404930.png)
