开发者

How to create a .app file of my java project to run on mac os

开发者 https://www.devze.com 2023-04-10 20:19 出处:网络
I am new to mac. I have a java project. I created a exe of that project using launch4j for window. Now I need to create a application for mac. I java project contains 5 java classes, also referred to

I am new to mac. I have a java project. I created a exe of that project using launch4j for window. Now I need to create a application for mac. I java project contains 5 java classes, also referred to some external jars. I found this site http://www.centerkey.com/mac/java/. But I struck when I tried to create the executable jar file. While working on window I used the following commands to create the class files and jar file.

To create class files..

javac one.java two.java -cp mail.jar;sqlite.jar Mainclass.java

To create the jar files for the classes created from the above command

jar cvf one.jar one.class

I used the 开发者_运维问答same command in mac terminal. But the first command to create the class files doesn't work. Any suggestion....


AFAIK Eclipse can create Mac app bundles for Java projects, though i'm not used it and can't say how it works.

Try Export -> Other -> Mac OS X Application bundle


First thing first, DO NOT USE javapackager

javapackager is the packaging and signing tool released with JDK 8; When JDK 11 deleted javaFX, javapackager is also deleted as a part of it.

That's why you may encounter below issue when you try to use javapackager:

The operation couldn’t be completed. Unable to locate a Java Runtime that supports javapackager.

How to create a .app file of my java project to run on mac os

I specifically mention it here because there are so many outdated info throughout the internet, cost me so much time going round in circles.

How I managed to package self-contained Java Application

  1. Use Eclipse to generate runnable JAR file

How to create a .app file of my java project to run on mac os

a. Right click your project -> Export.
b. Select Java -> Runnable JAR file.
c. Next.
d. Specify Export destination, e.g. ~/Downloads/jar/HelloSwing.jar .
e. "Library handling" select "Extract required libraries into generated JAR".
f. Finish.
  1. Use jpackage to package

    How to create a .app file of my java project to run on mac os

Input below command in the termnial:

jpackage --type pkg \
 --temp ~/Downloads/temp \
 --name HelloSwing \
 --input ~/Downloads/jar \
 --main-jar HelloSwing.jar \
 --main-class com.cheng.rostergenerator.ui.Main
  1. Get generated files

How to create a .app file of my java project to run on mac os

In the current terminal path ~/ , HelloSwing-1.0.dmg (51MB) is generated, that is the install file.

Under ~/Downloads/temp, HelloSwing.app is generated (125MB), double click to launch the App.

This is just a Hello World project of Java Swing, however, the application image size is a bit daunting.

Anyway, happy coding!

Reference: jpackage command doc


Update on the above: The "Export -> Other -> Mac OS X Application bundle" does not work for me on current Eclipse and Java stuff. Trying to get around this stumbling block I found the following: https://centerkey.com/mac/java/ I tried their sample for the tutorial, and it worked.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号