我正在尝试遵循此Apache CXF – JAX-WS – 简单教程,但构建下载的示例(开箱即用!)会创建一个客户端,该客户端在调用时拒绝运行,并发出此错误:
无法从 SampleWSCxfClient-0.0.1-SNAPSHOT.jar 加载 Main-Class 清单属性
我搜索以了解有关此问题的更多信息,并找到了这个 SO 答案,这促使我通过使用以下行打开 SampleWSCxfClient-0.0.1-SNAPSHOT.jar7-zip
并将其添加到文件名中来破解 SampleWSCxfClient-0.0.1-SNAPSHOT.jar:META-INF/MANIFEST.MF
Main-Class: com.areyes.sample.client.SampleWSClient
我通过简单地查看项目中唯一的 Java 文件找出了那个主类:
package com.areyes.sample.client;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.sample.service.SampleWebService;
public class SampleWSClient {
public SampleWSClient() {
ClassPathXmlApplicationContext classPathXmlAppContext = new ClassPathXmlApplicationContext("classpath:META-INF/beans.xml");
classPathXmlAppContext.start();
SampleWebService sampleWebService = (SampleWebService)classPathXmlAppContext.getBean("client");
System.out.println(sampleWebService.getDataFromWebService().getName());
System.out.println(sampleWebService.getDataFromWebService().getDescription());
System.out.println(sampleWebService.getDataFromWebService().getAge());
}
public static void main(String[] args){
new SampleWSClient();
}
}
然后我尝试再次调用 SampleWSCxfClient-0.0.1-SNAPSHOT.jar ,但这次它失败了:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/context/support/AbstractApplicationContext
Caused by: java.lang.ClassNotFoundException: org.springframework.context.support.AbstractApplicationContext
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: com.areyes.sample.client.SampleWSClient. Program will exit.
我如何使这个样本工作?
为了您的方便,可以从这里下载整个示例包 ZIP 。