3

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....

6
  • Launch the app. using Java Web Start. JWS works on Mac. Windows and *nix. Commented Oct 3, 2011 at 9:26
  • Thanks Andrew. But, I am not intended to download a app from web. I need to create an app for mac osx. Commented Oct 3, 2011 at 9:39
  • So the compile command "doesn' work". In what way? Do you get an error message? Commented Oct 3, 2011 at 9:49
  • So how do you intend to distribute your app. if not from the web? Do you intend to deliver it on moon-beams? Commented Oct 3, 2011 at 9:58
  • @ njlarsson: I got the following error while running the compile command -bash: dsn.jar: command not found -bash: imap.jar: command not found -bash: jxl-2.6.jar: command not found -bash: mail.jar: command not found -bash: mailapi.jar: command not found -bash: smtp.jar: command not found -bash: sqlitejdbc-v056.jar: command not found -bash: pop3.jar: command not found Commented Oct 3, 2011 at 10:18

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks corristo. It works. But I refer some folders in my code. That folders are not packed into the resulting application.
I added the application and folders referred in the code into a single folder. It works fine..
1

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.

javapackage error

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

eclipse

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 jpackage

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

enter image description here

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.