Running Java Jar File on Mac OS X

I have a Java application that works fine under windows, I go to the command line after creating the project, I execute the command

java -jar FileName.jar 

When I copied the project files to my Mac machine and ran 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 since java has to be portable no matter which underlying OS?

thanks

+4
source share
2 answers

Hi, I saw this sooner than here for an explanation.

Summary

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

+5
source

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

since Java must be portable no that the main OS

This is true if you stick with the java.* And javax.* .
com.sun.* Packages contain internal APIs, they are not available for non-Sun virtual machines, and many of them are platform specific.

+4
source

Source: https://habr.com/ru/post/1347065/


All Articles