简体   繁体   English

外部jar不在构建项目中加载。 NoClassDefFoundError

[英]External jars not loading in built project. NoClassDefFoundError

So, I have exported my project in both Netbeans and Eclipse and when I try to 因此,当我尝试将项目导出到Netbeans和Eclipse中时,

java -jar myproject.jar

I get this prompt 我得到这个提示

控制台提示

In my project I have some libraries which are located inside of src in Netbeans and out of src in Eclipse as it should (please correct me if I'm wrong) The libraries are included via: 在我的项目中,我有一些库,它们位于Netbeans的src内,而位于Eclipse的src内(应正确处理,如果我错了,请纠正我)。这些库通过以下方式包括:

Java Build Path > Add JARs... Java构建路径>添加JAR ...

I've done some research and it seems that I have to change my JAVA CLASSPATH or somethng like that but I don't know exactly how to do it. 我已经做了一些研究,似乎我必须更改JAVA CLASSPATH或类似的东西,但我不知道该怎么做。

The project works perfectly when I compile it and run it, but it crashes after I build it into a Jar file. 当我编译并运行该项目时,该项目可以完美运行,但是将其构建到一个Jar文件中后,它会崩溃。

By the way, if it isn't clear enough I'm on Ubuntu 14.04 顺便说一句,如果还不够清楚,我使用的是Ubuntu 14.04

You need to create the path for the jar files and pass it on the command line. 您需要为jar文件创建路径,并将其在命令行中传递。

Something like this: 像这样:

ftp_jar=${Utils_home}/bin/ftpClientUtil.jar
net_jar=${Utils_home}/bin/commons-net-3.3.jar
jsch_jar=${Utils_home}/bin/jsch-0.1.51.jar

java -cp .:$jsch_jar:$net_jar:$ftp_jar com.myplace.ftputils.SFTPClientUtil $*

Run your program as: 运行程序为:

java -cp .:[path-of-lib1.jar]:[path-of-lib2.jar] -jar myproject.jar

replace [path-of-libX.jar] with actual path of your libraries. 将[path-of-libX.jar]替换为您的库的实际路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM