我的主代码有两个类,主代码有两个引用
LookupService citylookup = new LookupService("D://GeoLiteCity.dat"...
FileReader fr =new FileReader("d:\\IP.txt");
我将它们导出到一个可执行的 jar 文件中,我得到 D://testIP.jar
和 D://testIP_lib/reference libraries...jar
我运行 java -jar testIP.jar
并且它有效。
但是,我修改了我对 linux 机器路径的引用 ex: /home/admin/GeoLiteCity.dat
和 /home/admin/IP.txt
并移动 textIP.jar
和 testIP_lib
和 GeoLiteCity.dat IP.txt
到 /home/admin/
我再次运行 java -jar testIP.jar
我收到错误
Exception in thread "main" java.lang.NoClassDefFoundError: com/maxmind/geoip/LookupService
at testIP.CountryLookupTest.main(CountryLookupTest.java:18)
我检查它们是 java 1.7..version 我不知道我应该在哪里设置? 谢谢。
最佳答案
听起来像是两个环境之间的类路径差异。检查两个环境中的CLASSPATH
环境变量,并检查jar 中MANIFEST.MF
文件中的Class-Path
条目。我怀疑 Eclipse 在 jar 内的 Manifest 文件中使用基于 Windows 的 Class-Path
条目构建了 jar。
关于java - eclipse execute jar文件在linux机器上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19939010/