一台机器上出现 NoSuchMethodError,但另一台机器上没有
我有这个应用程序,您可以使用 java 宏以批处理模式运行。我有一个使用 myjar.jar
的 mymacro.java
。为了简单起见,我将它们全部放在运行应用程序的同一目录中,因此类路径为 "./myjar.jar"
。
运行应用程序的命令是:
theapplication -classpath "./myjar.jar" -batch mymacro.java
其中-classpath
标记执行其所宣传的操作,即覆盖类路径。现在,它在我的 Windows XP PC 上运行良好。但是,当我在 Linux 集群上运行完全相同的事情时,我收到了 NoSuchMethodError
。
java.lang.NoSuchMethodError:
com.foo.bar.baz.theMethod(Ljava/lang/String;Ljava/lang/String;)I
我无法弄清楚这一点。相同的 .java、相同的 .jar、相同的 theMethod
。类路径再简单不过了。正在调用 myjar.jar
中的其他方法,没有任何错误。可能出了什么问题?
仅供参考,我在两台计算机上将 CLASSPATH
环境变量设置为 "."
以排除任何冲突。
编辑
在我的 Windows XP PC 上 java -version
的输出:
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) Client VM (build 19.1-b02, mixed mode)
在 Linux 集群上:
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)
I have this application which you can run in batch mode with java macros. I have a mymacro.java
that uses myjar.jar
. For simplicity's sake I put them all in the same directory from which I am running the application, so the classpath is "./myjar.jar"
.
The command to run the application is:
theapplication -classpath "./myjar.jar" -batch mymacro.java
where the -classpath
tag does what it advertises, i.e. override the classpath. Now this runs fine on my Windows XP PC. However, I get a NoSuchMethodError
when running the exact same thing on a Linux cluster.
java.lang.NoSuchMethodError:
com.foo.bar.baz.theMethod(Ljava/lang/String;Ljava/lang/String;)I
I can't figure this one out. Same .java, same .jar, same theMethod
. The classpath can't get any simpler. Other methods in myjar.jar
are being called without any errors. What could be going wrong?
FYI, I set the CLASSPATH
environment variable to "."
on both machines to rule out any conflicts.
EDIT
Output of java -version
on my Windows XP PC:
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) Client VM (build 19.1-b02, mixed mode)
On Linux cluster:
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于使用的 JAR 文件的文件名,我曾经遇到过类似的问题。就我而言,我有多个 JAR 文件,例如
a.jar
、b.jar
、m.jar
和N.jar< /代码>。
m.jar
和N.jar
中都有重复的单个类。在 Windows 上,所有用作
N.jar
的内容总是在m.jar
之后加载。但熬夜后,我发现 *nix 上的问题是由于首先加载N.jar
,然后加载a.jar
,b.jar
、m.jar
因为文件名在 *nix 上区分大小写,与 Windows 不同。只要确保您没有任何类似的问题即可。
I faced a similar issue once due to the file names of the JAR files used. In my case, I had multiple JAR files like
a.jar
,b.jar
,m.jar
andN.jar
. A single class was duplicated in bothm.jar
andN.jar
.On Windows, everything used to work as
N.jar
was always getting loaded afterm.jar
. But after burning much midnight oil, I discovered that the issue on *nix was due to the fact thatN.jar
gets loaded first followed bya.jar
,b.jar
,m.jar
as file names are case sensitive on *nix unlike on Windows.Just make sure you don't have any similar issue.
啊。该应用程序包含一个 NetBeans 模块,该模块基本上包含与我的 JAR 文件的早期版本相同的代码。因此,我的 java 宏优先访问旧 NBM 中的方法,而不是新 JAR 文件中的方法。
当我卸载 NBM 后,错误消失了。
浪费一整天工作的好方法!
Argh. The application contained a NetBeans module that basically contained the same code as an earlier version of my JAR file. So my java macro was preferentially accessing the methods in the older NBM, not those in my newer JAR file.
The error went away when I uninstalled the NBM.
Nice way to waste a full day of work!
吗
存在于新版本的 jar 中 ?
如果不是,则可能是 mymacro.java 是针对包含它的 jar 版本进行编译的
Is
present in the new version of the jar?
If it is not is probable that mymacro.java was compiled againt a version of the jar which contained it