当从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运行它,但似乎都不起作用。
答案 0 :(得分:0)
除此之外:
尝试使用java -cp &#34; / HTML /的Myproj / API /目标/类:/html/myProj/API/target/API-1.0.0-BUILD-SNAPSHO T / WEB-INF / LIB / &#34; com.api.spring.management.CheckStatus。 (注意最后的) - Tunaki
事实证明我的一个依赖关系并未设置为在战争中导出,所以在我修复它之后一切正常。