0

I can't create Windows software through Eclipse. Using "Run" does run the app as it should, but I would like to start it without Eclipse, preferably as an independent Windows app, using a mere double-click. Although this suggests several approaches, they all require additional knowledge that I do not posses.

I have tried using Launch4J but it also requires additional knowledge. I am astounded that it is so difficult to create a simple Windows-Java-app.

EDIT I am using this pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>1.0.0</version>
<name>baz</name>
<description></description>

<dependencies>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>com.zenjava</groupId>
            <artifactId>javafx-maven-plugin</artifactId>
            <version>8.8.3</version>
            <configuration>
                <mainClass>application.Main</mainClass>
                <updateExistingJar>true</updateExistingJar>
                <skipCopyingDependencies>true</skipCopyingDependencies>
                <useLibFolderContentForManifestClasspath>true</useLibFolderContentForManifestClasspath>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>build-jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>

But Eclipse gives this error message:

Failed to execute goal com.zenjava:javafx-maven-plugin:8.8.3:build-jar

the goal being

clean compile package -e

Maven is installed, trying to run it with minimal appendancies.

Socrates
  • 103
  • 1
  • 3
  • 8
  • My project can bundle your app into an MSI file and even bundle in the JRE so end user does not need Java installed. It is a bit complex though. https://github.com/pquiring/javaforce – Peter Quiring Jan 11 '19 at 20:42
  • @stdunbar The post you are pointing to requires advanced knowledge of Java programming, including additional software. Wow, is it still so hard to develop a simple Java app which does the same as clicking the run-button in Eclipse? – Socrates Jan 11 '19 at 21:45

3 Answers3

2

First of all, you can't create "Windows-Java-App". Java applications run on JVM (Java Virtual Machine) which means you wont be getting an exe file. What you need is a JAR file. For info on how to create a JAR file in Eclipse, see here: https://stackoverflow.com/a/21110972/4440179

For JavaFX follow this guide: https://wiki.eclipse.org/Efxclipse/Tutorials/Tutorial1

JimS
  • 349
  • 1
  • 4
  • 19
  • 1
    It is possible to create "Windows-Java-Apps". You can even bundle the JRE into the MSI that is distributed so the user need not have Java installed. Java is just a DLL when you think about it. – Peter Quiring Jan 11 '19 at 20:38
  • I did export the app as a "Runnable Jar file" with different selections ("Extract required [...]", "Package required [...]", "Copy required [...]". Double clicking the resulting JAR file did not start the app. – Socrates Jan 11 '19 at 20:40
  • 1
    Yea, this answer doesn't really help Op at all. As Peter says, you *can* create "Windows-Java-Apps", but also this answer just doesn't tell Op anything about making the Jar able to run as a JavaFX application. – xtratic Jan 11 '19 at 20:41
  • @Alleavingmarks does your app have a GUI? – JimS Jan 11 '19 at 20:42
  • 1
    @JimS Op says, it's JavaFX. There's no point in JavaFX without a GUI my dude.. – xtratic Jan 11 '19 at 20:43
  • @JimS Yes, that is why JavaFX is used. – Socrates Jan 11 '19 at 20:44
  • @Alleavingmarks sorry didn't notice the JavaFX in the title. Anyways, without any more info about the app, code etc. I can't tell what's wrong. But this is the way to create an executable. – JimS Jan 11 '19 at 20:48
  • 1
    @JimS Since this does not answer Ops question I recommend deleting this. – xtratic Jan 11 '19 at 20:59
  • @xtratic He asked quoting "I would like to start it without Eclipse, preferably as an independent Windows app, using a mere double-click.". He asks for a JAR file. I redirected him to an answer with steps on how to create one in Eclipse. How does this not help OP? – JimS Jan 11 '19 at 21:03
  • 1
    Your answer does not work for Ops request for a double-clickable JavaFX Jar. – xtratic Jan 11 '19 at 21:04
  • @JimS "He asks for a JAR file." All that I am asking for is a minimal approach to run a (Java-)app on Windows with minimal effort. – Socrates Jan 11 '19 at 21:19
  • 1
    @Alleavingmarks `java -jar jar_name.jar` run this through the command line to check if your app is throwing an exception. – JimS Jan 11 '19 at 21:29
  • @JimS Building a JavaFX Jar is not the same as building a normal Jar. – xtratic Jan 11 '19 at 21:49
  • @Alleavingmarks I edited my answer for JavaFX apps. – JimS Jan 11 '19 at 21:55
  • @JimS This command-line approach does start it as inteded. Thank you. The main problem is still that I do not have a mere double-click approach. – Socrates Jan 11 '19 at 21:56
2

Launch4j I know it can make an exe Wrapper over the Java, and it is cross platform.

Check here: http://launch4j.sourceforge.net/

Marvin
  • 598
  • 5
  • 14
  • It requires additional knowledge. Before you tell me to simply learn it, try developing a minimal approach. – Socrates Jan 11 '19 at 20:42
  • What additional knowledge are you talking about ? You select output .exe file, and input .jar file. Maybe they changed something lately, but I remember you need 1-2 clicks. – Marvin Jan 11 '19 at 23:20
1

I recommend making a Maven project to help you build an executable JavaFX Jar.

Firstly you'll need to make sure that Eclipse has the Maven plugin Help -> About Eclipse IDE and make sure that Eclipse.org - m2e is installed.

Then make a Maven project New -> Other.. -> Maven Project, fill in the basic stuff to create the project then put your source files under src/main/java of this new project.

There should be a pom.xml file in the root of this new project; This file helps manage your project dependencies and build process. To make easily build an executeable add the below plugins to your pom.xml file to modify the build process.

Then you can just right click your pom.xml then Run As -> Maven Build ... then put clean compile package -e as your goals, refresh your MyProject/target directory and find your Jar under MyProject/target/javafx/app/jarname.jar

Also, if you want, you can look into using the launch4j maven plugin to have maven build the native executable for you, else your Jar will require the user have Java installed but it will still be a double-clickable JavaFX Jar.


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>1.0.0</version>
<name>baz</name>
<description></description>

<dependencies>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>com.zenjava</groupId>
            <artifactId>javafx-maven-plugin</artifactId>
            <version>8.8.3</version>
            <configuration>
                <mainClass>path.to.my.Main</mainClass>
                <updateExistingJar>true</updateExistingJar>
                <skipCopyingDependencies>true</skipCopyingDependencies>
                <useLibFolderContentForManifestClasspath>true</useLibFolderContentForManifestClasspath>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>build-jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>
xtratic
  • 4,600
  • 2
  • 14
  • 32
  • Is Maven a requirement for running any Java-app on Windows? I doubt it. – Socrates Jan 11 '19 at 20:43
  • No, maven is just a build tool. It makes it easier for you to build your projects. I also had trouble making an executable JavaFX application until I used maven. – xtratic Jan 11 '19 at 20:43
  • I tried Maven, but I get the error message "No goals have been specified for this build". Professionals might know right away which goals need to be specified, but I simply want to run my app ... – Socrates Jan 11 '19 at 20:59
  • Sorry, right click `Run As -> Maven Build ...` then put `clean compile package -e` as your goals – xtratic Jan 11 '19 at 21:02
  • I get the "The goal you specified requires a project to execute but there is no POM in this directory" message. – Socrates Jan 11 '19 at 21:09
  • Didn't you click on the `pom.xml` file? Is your project not a Maven Java project? It should have a little `m` to the left of the `J` over your project folder. Please paste the contents of your `pom` into your question. – xtratic Jan 11 '19 at 21:10
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/186567/discussion-between-xtratic-and-al-leaving-marks). – xtratic Jan 11 '19 at 21:12
  • I put the pom.xml file in the root, but the following error appears when I try to run it: "Malformed POM" – Socrates Jan 11 '19 at 21:15
  • Sorry, I had only pasted the `` section of the `pom` the full `pom` should look more like what I have edited into my answer now. You're almost there, once you understand Maven a little more it will make life much easier for you. Also you will need to specify the path to your main JavaFX class in place of `path.to.my.Main` – xtratic Jan 11 '19 at 21:17
  • I get an error message consisting of "BUILD FAILURE" and "Failed to execute goal com.zenjava:javafx-maven-plugin:8.8.3:build-jar". – Socrates Jan 11 '19 at 21:26
  • please add the contents of your `pom.xml` to your question. Also, let's continue in chat, please click the link above. – xtratic Jan 11 '19 at 21:29