简体   繁体   中英

How to build a jar for Mac OS X 10.6 from windows?

I have some problem with my java application, I did build it with Eclipse under Win7 (64bit): it does not work on Snow Leopard 10.6.8. The error is: "The JAR file .... could not be launched".

I have checked if Java was installed on Mac and yes, there is JRE with the 64 bit option first to execute.

My Application does not make use of any particular library:

import java.net.*;
import java.io.IOException;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

.. so I really can't understand why it doesn't work on Mac, any suggestion? Many thanks for your help

UPDATE: Yes, it works on Windows, I use Java 6 and unfortunately I don't have OS X, I've sent my application to a friend who has OS X, so I can't open the Terminal (and my friend never opened it probably...). Thanks for your suggestions anyway.

UPDATE2:This is the output message

13/03/12 19.09.30       [0x0-0x2d52d5].com.apple.JarLauncher[44675]     Exception
in thread "main"
13/03/12 19.09.30       [0x0-0x2d52d5].com.apple.JarLauncher[44675]     java.lang.UnsupportedClassVersionError:
Main : Unsupported major.minor version 51.0
13/03/12 19.09.30       [0x0-0x2d52d5].com.apple.JarLauncher[44675]             at
java.lang.ClassLoader.defineClass1(Native Method)
13/03/12 19.09.30       [0x0-0x2d52d5].com.apple.JarLauncher[44675]             at
java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
13/03/12 19.09.30       [0x0-0x2d52d5].com.apple.JarLauncher[44675]             at
java.lang.ClassLoader.defineClass(ClassLoader.java:615)
13/03/12 19.09.30       [0x0-0x2d52d5].com.apple.JarLauncher[44675]             at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
13/03/12 19.09.30       [0x0-0x2d52d5].com.apple.JarLauncher[44675]             at
java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
13/03/12 19.09.30       [0x0-0x2d52d5].com.apple.JarLauncher[44675]             at
java.net.URLClassLoader.access$000(URLClassLoader.java:58)
13/03/12 19.09.30       [0x0-0x2d52d5].com.apple.JarLauncher[44675]             at
java.net.URLClassLoader$1.run(URLClassLoader.java:197)
13/03/12 19.09.30       [0x0-0x2d52d5].com.apple.JarLauncher[44675]             at
java.security.AccessController.doPrivileged(Native Method)
13/03/12 19.09.30       [0x0-0x2d52d5].com.apple.JarLauncher[44675]             at
java.net.URLClassLoader.findClass(URLClassLoader.java:190)
13/03/12 19.09.30       [0x0-0x2d52d5].com.apple.JarLauncher[44675]             at
java.lang.ClassLoader.loadClass(ClassLoader.java:306)
13/03/12 19.09.30       [0x0-0x2d52d5].com.apple.JarLauncher[44675]             at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
13/03/12 19.09.30       [0x0-0x2d52d5].com.apple.JarLauncher[44675]             at
java.lang.ClassLoader.loadClass(ClassLoader.java:247)

You should be able to just double click the jar file, however, if anything goes wrong, the output will go to the system log. Get your friend to double click the jar file with the Console app running (in the Utilities folder) and showing all messages from system log queries.

In the long term, if you want a nice icon etc, you will need to create an OS X bundle for the jar and supporting files. There used to be a tool called Jar Bundler for doing this (only runs on OS X) but my copy of dev tools no longer has it. I'm sure you can get it from somewhere though.

First of all I made sure I had the same JRE, and apparently mine was the JRE7, so in Eclipse I changed it. Also I did modify the Run/Debugging Configurations: in Environment -> Add new variable DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib Which should help the execution on OsX. Finally I exported everything again to JAR and it worked on Mac as well.

Thanks for your collaboration.

I hope this answer could help somebody else...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM