简体   繁体   English

如何从Windows构建Mac OS X 10.6的jar?

[英]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. 我的Java应用程序存在一些问题,我确实是在Win7(64位)下使用Eclipse构建的:它在Snow Leopard 10.6.8上不起作用。 The error is: "The JAR file .... could not be launched". 错误为: "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. 我检查了Mac上是否安装了Java,是的,首先执行带有64位选项的JRE。

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? ..所以我真的不明白为什么它不能在Mac上运行,有什么建议吗? 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...). 更新:是的,它可以在Windows上运行,我使用Java 6,但是不幸的是我没有OS X,我已经将应用程序发送给了拥有OS X的朋友,所以我无法打开终端(我的朋友从不打开它可能...)。 Thanks for your suggestions anyway. 无论如何,谢谢您的建议。

UPDATE2:This is the output message UPDATE2:这是输出消息

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. 您应该可以双击jar文件,但是,如果出现任何问题,输出将进入系统日志。 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. 让您的朋友在运行控制台应用程序(在“实用工具”文件夹中)上双击jar文件,并显示来自系统日志查询的所有消息。

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. 从长远来看,如果您想要一个漂亮的图标等,则需要为jar和支持文件创建OS X捆绑软件。 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. 曾经有一个名为Jar Bundler的工具来执行此操作(仅在OS X上运行),但是我的开发工具副本不再具有此功能。 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. 首先,我确保我具有相同的JRE,显然我的是JRE7,因此在Eclipse中我对其进行了更改。 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. 我也修改了“运行/调试配置”:在环境->添加新变量DYLD_FALLBACK_LIBRARY_PATH = / opt / local / lib,这将有助于在OsX上执行。 Finally I exported everything again to JAR and it worked on Mac as well. 最后,我再次将所有内容导出到JAR,它也可以在Mac上使用。

Thanks for your collaboration. 感谢您的合作。

I hope this answer could help somebody else... 我希望这个答案可以帮助其他人...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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