在 Mac OS X 上运行 Java Jar 文件

发布于 2024-10-31 02:51:21 字数 2035 浏览 1 评论 0原文

我有一个在Windows下完美运行的Java应用程序,我在构建项目后进入命令行,执行命令

java -jar FileName.jar 

当我将项目文件复制到我的Mac机器并执行相同的命令时,我出现以下错误:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/sun/security/auth/module/NTSystem
    at androidchat.AndroidChatView.<init>(AndroidChatView.java:48)
    at androidchat.AndroidChatApp.startup(AndroidChatApp.java:19)
    at org.jdesktop.application.Application$1.run(Application.java:171)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:678)
    at java.awt.EventQueue.access$000(EventQueue.java:86)
    at java.awt.EventQueue$1.run(EventQueue.java:639)
    at java.awt.EventQueue$1.run(EventQueue.java:637)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:648)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: java.lang.ClassNotFoundException: com.sun.security.auth.module.NTSystem
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

为什么发生这种情况是因为无论底层操作系统是什么,java都应该是可移植的?

谢谢

I have a Java application that is running perfectly under windows, i go to the command line after building the project, execute the command

java -jar FileName.jar 

When i copied the project files to my Mac machine and executed the same command, i have the following error:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/sun/security/auth/module/NTSystem
    at androidchat.AndroidChatView.<init>(AndroidChatView.java:48)
    at androidchat.AndroidChatApp.startup(AndroidChatApp.java:19)
    at org.jdesktop.application.Application$1.run(Application.java:171)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:678)
    at java.awt.EventQueue.access$000(EventQueue.java:86)
    at java.awt.EventQueue$1.run(EventQueue.java:639)
    at java.awt.EventQueue$1.run(EventQueue.java:637)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:648)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: java.lang.ClassNotFoundException: com.sun.security.auth.module.NTSystem
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

why is this happening as java is supposed to be portable no matter what the underlying OS is ?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

真心难拥有 2024-11-07 02:51:21

嘿,我之前见过这个,请参阅此处解释

摘要

sun.* 软件包不是受支持的公共接口的一部分。
不保证直接调用 sun.* 包的 Java 程序可以在所有 Java 兼容平台上运行。事实上,即使在同一平台上的未来版本中,也不能保证这样的程序能够工作。

Hey there I have seen this before see here for an explanation

Summary

The sun.* packages are not part of the supported, public interface.
A Java program that directly calls into sun.* packages is not guaranteed to work on all Java-compatible platforms. In fact, such a program is not guaranteed to work even in future versions on the same platform.

七堇年 2024-11-07 02:51:21

显然您正在使用 com.sun.security.auth.module.NTSystem,一个仅在基于 Win NT 的系统上可用的内部 API。

因为java应该是可移植的,否
无论底层操作系统是什么

只要您坚持使用 java.*javax.* 包,这都是正确的。
com.sun.* 包包含内部 API,它们在非 Sun VM 上不可用,并且其中许多是特定于平台的。

Apparently you are using com.sun.security.auth.module.NTSystem, an internal API that's only available on Win NT-based systems.

as java is supposed to be portable no
matter what the underlying OS is

This is true as long as you stick to java.* and javax.* packages.
com.sun.* packages contain internal APIs, they are not available on non-Sun VMs, and many of them are platform-specific.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文