即使jar文件位于工作目录中也无法找到类 [英] Cannot find class even when jar file is in working directory

查看:163
本文介绍了即使jar文件位于工作目录中也无法找到类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力让我的Java程序在AIX上运行。我在Windows上使用Eclipse创建了一个可运行的Jar文件,下面的 jRams.jar 。我一直在遇到找不到类的错误,直到最后我将所有外部库放在同一目录中。

I am struggling to get my Java program to run on AIX. I used Eclipse on Windows to create a runnable Jar file, jRams.jar below. I kept on getting a class not found error, until finally I put all the external libraries in the same directory.

$ ls
JAXB2_20081030.jar
JAXB2_20110601.jar
activation.jar
asjava.jar
commons-beanutils-1.8.3.jar
commons-beanutils-bean-collections-1.8.3.jar
commons-beanutils-core-1.8.3.jar
commons-codec-1.5.jar
commons-collections-3.2.1.jar
commons-configuration-1.6.jar
commons-digester-2.1.jar
commons-jxpath-1.3.jar
commons-lang-2.6.jar
commons-logging-1.1.1.jar
commons-logging-adapters-1.1.1.jar
commons-logging-api-1.1.1.jar
jRams.jar
jaxb-api.jar
jaxb-impl.jar
jaxb-xjc.jar
jaxb1-impl.jar
jremote.jar
jsr173_1.0_api.jar
log4j-1.2.16.jar
netty-3.2.4.Final.jar
$

仍然,我得到未找到类错误。

Still, I get the class not found error.

$ java -jar jRams.jar
The java class is not found:  com.jbase.jremote.JRemoteException

jremote.jar 肯定包含JRemoteException。为什么这样行不通?

jremote.jar definitely contains JRemoteException. Why isn't this working?

更新

感谢您的支持点对点的答案。现在,我更好地了解了Java应用程序和清单文件的性质。

Thank you for your straight-to-the-point answers. I now understand the nature of a java application and a manifest file far better.

原来,我的ftp客户端是以ASCII模式而不是二进制模式进行传输的,所以jar文件是腐败。尽管如此,我还是学到了很多。

Turns out my ftp client was transferring in ASCII mode and not Binary, so the jar files were corrupt. I have learned a great deal, nonetheless.

推荐答案

使用 -jar 选项,您需要在清单文件。只是将必需的jar文件放在同一目录中是不会做的。

When using the -jar option, you need to specify which jar-files should be on your class path in the manifest file. Just having the required jar files in the same directory won't do it.

在清单中添加一行,内容为:

Add a line in your manifest that says:

Class-Path: JAXB2_20081030.jar:JAXB2_20110601.jar:....:netty-3.2.4.Final.jar

或跳过 -jar 选项并使用

java -cp JAXB2_20081030.jar:....:netty-3.2.4.Final.jar:jRams.jar pkg.JRamsMain

,它应该可以正常工作。

and it should work fine.

(请注意,在* nix系统上,而不是Windows计算机,应使用而不是; 分隔类路径中的jar文件。)

(Note that on *nix systems, as opposed to Windows machines, the jar files in the class paths should be separated using : instead of ;.)

进一步阅读:

  • The Java Tutorials: Adding Classes to the JAR File's Classpath

这篇关于即使jar文件位于工作目录中也无法找到类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆