maven java.lang,第一次使用maven后的Java.lang.NoClassDefFoundError?

I've been creating a soap server with java for my company and I just recently switched over to using Bone-CP and Maven to import all the required 3rd party programs. After I finished implementing bone-CP I used the server command

jar -cvfm SoapServer.jar manifest.txt SoapServer

And when I transfered it to my server and tried to run it I got this error:

Exception in thread "main" java.lang.NoClassDefFoundError: SoapServer/SoapServer (wrong name: com/test/SoapServer/SoapServer)

at java.lang.ClassLoader.defineClass1(Native Method)

at java.lang.ClassLoader.defineClass(ClassLoader.java:791)

at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)

at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)

at java.net.URLClassLoader.access$100(URLClassLoader.java:71)

at java.net.URLClassLoader$1.run(URLClassLoader.java:361)

at java.net.URLClassLoader$1.run(URLClassLoader.java:355)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:354)

at java.lang.ClassLoader.loadClass(ClassLoader.java:423)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)

at java.lang.ClassLoader.loadClass(ClassLoader.java:356)

at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

The only think I can think of causing the problem is that maven doesn't package the required JARs with the program? If that's the case do I just need to download them and add them to the class path?

解决方案

If you need all of your dependencies to be packed in the executable jar then configure your pom like

maven-jar-plugin

true

lib/

com.something.YourMainClass

above block will add all the library in lib/ to classpath in manifest classpath entry

and to copy all the dependencies to lib directory

org.apache.maven.plugins

maven-dependency-plugin

2.1

copy-dependencies

package

copy-dependencies

${project.build.directory}/lib

false

false

true

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值