【问题标题】:Run Spring batch with CommandLineJobRunner error impossible to find or load main class CommandLineJobRunner运行带有 CommandLineJobRunner 错误的 Spring 批处理,无法找到或加载主类 CommandLineJobRunner
【发布时间】:2019-09-30 15:04:56
【问题描述】:

我是 Spring 批处理的新手,想使用 CommandLineJobRunner 类通过命令行运行批处理,因此我将生成的 jar 文件和 CommandLineJobRunner 复制到我的桌面,并在运行以下命令后:

Java -cp spring-batch-example.jar org.springframework.batch.core.launch。支持。 CommandLineJobRunner 类路径:/jobs/file-import-job。 xml simpleFileImportJob

导致此错误(无法找到或加载主 org.springframework.batch.core.launch.support.CommandLineJobRunner)。 我认为我应该处理类路径,我不知道该怎么做。

【问题讨论】:

    标签: jar spring-batch


    【解决方案1】:

    您还需要将 Spring Batch jar 添加到类路径中,例如:

    java -cp spring-batch-example.jar:lib/* org.springframework.batch.core.launch.support.CommandLineJobRunner classpath:/jobs/file-import-job.xml simpleFileImportJob
    

    lib 包含 Spring Batch jar 及其依赖项。请注意,如果您在 Windows 上,则需要使用 ';'而不是 ':' 来分隔类路径条目。

    我建议使用maven shade plugin或类似的插件来创建一个超级jar,或者使用Spring Boot,它会为你做的。在这两种情况下,您都可以使用:

    java -jar spring-batch-example.jar
    

    【讨论】:

    • 感谢 Mahmoud 的回答,我添加了 spring batch jars 但我仍然有同样的错误,我编辑了问题以放置屏幕截图
    • maven-shade-plugin 创建一个包含所有所需依赖项的 jar,因此它解决了我的问题。
    • 对于 Gradle,请使用 gradle shadow 插件。这个讨论展示了如何将它专门用于spring:discuss.gradle.org/t/…
    猜你喜欢
    • 2018-04-09
    • 1970-01-01
    • 1970-01-01
    • 2015-01-30
    • 2012-04-01
    • 1970-01-01
    • 2021-10-03
    • 2020-10-10
    • 1970-01-01
    相关资源
    最近更新 更多