Reputation: 63
I recently switched from Windows to Mac and tried to open an executable .jar file on my Mac by clicking the icon in Finder. Somehow it turned out that mac is not able to execute a .jar file except using the Terminal.
After some research, I got to know that "javapackager" and "Jar Bundler" are ways to make it runnable, but I could not find any functional download for these programs.
So is there any way to make these programs runnable?
Upvotes: 3
Views: 3164
Reputation: 56
Actually, I am new to Mac, and I just want to try, and it worked. What I do is, creating a maven project and adding some plugins to create executable jar file. Maven plugins side;
<build>
<finalName>myExecutableApp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/libs
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>libs/</classpathPrefix>
<mainClass>
com.rcelik.executable.ExecutableMavenJar
</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
And some swing code to understand if executable jar file is running.
public class ExecutableMavenJar {
public static void main(String[] args) {
JFrame f=new JFrame();
JButton b=new JButton("click");
b.setBounds(130,100,100, 40);
f.add(b);
f.setSize(400,500);
f.setLayout(null);
f.setVisible(true);
}
}
After code part, I just package the project with maven. And I could run the executable jar file by double clicking on it. Can you please check this way of creating the executable jar file. By the way, MacOs opens the jar file with JavaLauncher.app which is default.
Upvotes: 0
Reputation: 102814
The distribution model of shipping a jar
file to a user and then expecting them to just know what to do with it is obsolete - oracle has more or less acknowledged that the vast majority of desktop java apps are not now and never were deployed that way: They have stopped supporting the idea of a 'JRE'. This is how it more or less officially (in that oracle's products clearly endorsed this model) used to work:
This is obsolete, in that oracle has stopped shipping a JRE and has stopped wanting to be 'on the hook' for having a relationship with every end user system on the planet to support those JREs.
Thus, you are labouring under an old deployment mechanism. If you're the owner of this app, update to a new model (such as using jlink
and jpackager
to make a .app
and ship it in a .dmg
like normal mac apps, also, this lets you sign it, have a nice icon, etc). If you're not, time to talk to the maintainer of this app and tell them to do that. Until then, here's how you work around this:
Upvotes: 3