How can i create executable apple .app file from my java .jar file?

余生长醉 提交于 2019-12-21 23:49:31

问题


I have created an executable java Swing .jar application. It works fine on Windows. The application hierarchy is :

application.jar

images(Folder) .......... Contains all images the application uses.

libraries(Folder) ....... Contains all external jar libraries the application uses.

bundles(Folder) ......... Contains all bundle files the application uses.

database(Folder) ........ Contains the database files the application uses.

All the above folders exist outside the jar file. Now i am trying to create a Mac executable file (.app) from "application.jar" to run it on Mac so i used the "Jar Bundler" as specified here but when i run the output application.app file nothing happens, nothing runs and i can't even debug it.

I think the main reason is that it can't see the external folders. So is it impossible to create a .app file if the application has external folders ? And is there a way to debug the .app file to see what's going on ?


回答1:


Most likely the problem is your working directory.

  • When you run an executable JAR file by double-clicking it, the working directory is the parent directory of the JAR file.

  • By default, the working directory of an application bundle is its parent directory. If you package the external folders into the application bundle they will be located under $APP_PACKAGE/Contents/Resources.

So the assumption about the working directory that you make for an executable JAR file does not hold for an application bundle.

In order to set the working directory to the resources directory, add

<key>WorkingDirectory</key>
<string>$APP_PACKAGE/Contents/Resources</string>

to the Info.plist file of your bundle.

In case you know nothing about application bundles, please read this document.




回答2:


Nothing runs, and i can't even debug it.

Diagnostic output from the launch process may be obtained as follows:

$ export JAVA_LAUNCHER_VERBOSE
$ ./YourApplication.app/Contents/MacOS/JavaApplicationStub

There's a related example here.




回答3:


This might help: AppBundler by Josh Marinacci




回答4:


I am not sure about your exact directory hierarchy. But on a Mac with Xcode installed is an application called "Jar Bundler". It exist for exact that purpose you are asking for. BTW, Mac application use the suffix .app, that is right. But they are not files. Thery are directories.



来源:https://stackoverflow.com/questions/7525060/how-can-i-create-executable-apple-app-file-from-my-java-jar-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!