来自命令行的错误 运行 Java cron Spring

Error running Java cron from command line with Spring

当 运行 从 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

我已经在所有 spring jar 所在的类路径上传递了 lib 文件夹。我也通过 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 中导出,所以在我修复后一切正常。