java - 使用 Spring 从命令行运行 Java cron 时出错

标签 java eclipse spring cron

当从 eclipse 作为独立应用程序运行时,这一切都有效。

我的Java主要方法:

public static void main(String[] args) throws MessagingException, IOException, RequestErrorFault, UnexpectedErrorFault, ServerErrorFault {
        ApplicationContext context = new FileSystemXmlApplicationContext("src" + File.separator + "main" + File.separator + "webapp" + File.separator + "WEB-INF" + File.separator + "spring" + File.separator + "appServlet" + File.separator + "cron-context.xml");

        CheckStatus checkStatus = context.getBean(CheckStatus.class);


        List<Integer> requestIds = checkStatus.getRequests(); 
        checkStatus.processRequests(requestIds);
    }

输出:

java -cp /html/myProj/API/target/classes:/html/myProj/API/target/API-1.0.0-BUILD-SNAPSHOT/WEB-INF/lib  com.api.spring.management.CheckStatus
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    at java.lang.Class.getMethod0(Class.java:3018)
    at java.lang.Class.getMethod(Class.java:1784)
    at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more

我已传入类路径上的 lib 文件夹,其中所有 spring jar 都存在。我也尝试通过 mvnexec:java 运行它,但似乎都不起作用。

最佳答案

除此之外:

Try with java -cp "/html/myProj/API/target/classes:/html/myProj/API/target/API-1.0.0-BUILD-SNAPSHO‌​T/WEB-INF/lib/" com.api.spring.management.CheckStatus. (note the / at the end) – Tunaki

事实证明,我的一个依赖项没有设置为在 war 中导出,所以在我修复后,一切都正常了。

关于java - 使用 Spring 从命令行运行 Java cron 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32742254/

相关文章:

java - 将对象数组从 PLSQL 传递到 Java 函数时出错

eclipse - 拖放环境开始在 gwt 中开发

java - 是否有一个 "Spring 3 MVC way"来监听结束 session 事件?

java - 由于 SeekBar 元素,Android 强制关闭

java - 嵌套对象列表的 Spring 配置属性元数据 json

java - Spring自定义 Autowiring

java - 无法从 MongoDB 中的文档数组中删除最低分数

javax.servlet.ServletException : ICEfaces requires the PersistentFacesServlet

java - 短语查询 : are the terms strictly searched in their order?

android - Modbus tcp 安卓应用