0

I'm running Ubuntu 16.04 LTS with IntelliJ Idea Community Edition.

Having finished my desktop application I wish to export to run as a standalone application. I have JRE9 installed.

Following the quick 60 seconds tutorial in this video, which is also the same as on the IntelliJ web site tutorial.

So I go to Project Structure, Artifacts, Add, Go to JavaFX tab, select the main class, OK, the build the artifact, open the containing folder and...

Double clicking the .jar file says it's not executable, so I chmod +x file.jar to make it executable, and that still doesn't run.

So in the terminal I go to the directory and type java -jar file.jar but that says Error: Could not find or load main class sample.Main.

But I've selected the main class in the Artifact window.

Any ideas how to fix this? Thanks.

UPDATE

My directory/file/file contents structure looks like this:

WorkingDirectory
    Myjar.jar
        META-INF
            MANIFEST.MF
                Manifest-Version: 1.0
                Created-By: JavaFX Packager
                Main-Class: sample.Main
                Class-Path: 
                Permissions: sandbox
                JavaFX-Version: 9.0.4
        sample
            Main.class
                public static void main(String[] args) { launch(args); }
    MyLib1.jar
    MyLib2.jar

I also have .jar files

  • This is not an issue of file rights. It's an issue of java not being able to use `sample.Main` as entry point of the program. Does this class contain a `main` method with the correct signature? – fabian Apr 30 '18 at 16:09
  • @fabian the `.jar` file contains a folder called `sample` in which is a class file called `Main.class`. To investigate further I extracted the `.jar` file into a regular directory structure, and navigated directly into the `sample` folder and `java Main.class` won't even execute. So I did a bit of digging around. Maybe it's becuase `sample.Main` cannot find the two libraries I'm using? So in the Project Structure / Artifact folder I double clicked all my `.jar` dependencies in the right hand side, so they then appeared in my build `.jar` file, and rebuilt. But that doesn't work either. –  Apr 30 '18 at 16:14
  • 1
    You could do something like `javap -v Main.class | find "public static void main"` to check for a main method in that class (or simply look at the source code)... Not being able to load referenced classes should result in a error mentioning the class that could not be loaded... – fabian Apr 30 '18 at 16:23
  • @fabian if I type `javap -v Main.class | find "public static void main"` in the extracted directory structure, inside `sample`, it says `find: ‘public static void main’: No such file or directory` :-/ ... but there's definitely the following function in my `Main.java` file: `public static void main(String[] args) { launch(args); }` –  Apr 30 '18 at 16:34
  • Perhaps an issue with modules? Have you tried to run the jar specifying module+main class name? – fabian Apr 30 '18 at 16:40
  • 1
    @Antinous See http://stackoverflow.com/a/42660624/104891, https://stackoverflow.com/a/45169655/104891 and http://stackoverflow.com/a/42200519/104891. – CrazyCoder Apr 30 '18 at 19:04
  • @CrazyCoder I've updated my question to show my file directory/file/jar/contents structure. I notice the `MANIFEST.MF` Class-Path is empty, yet the project uses the `MyLib1.jar` and `MyLib2.jar` jars. Is this correct? No idea why `java -jar Myjar.jar` won't work. I mean `sample.Main` contains a `main` function... –  May 01 '18 at 09:38
  • @fabian do you mean run something like: `java -jar JavaFXApp.jar j1.jar j2.jar` ? where `j1`, `j2` are external jars in the same directory as `JavaFXApp.jar` ? This is a nightmare, finished my app but can't do this simple thing lol. I've recreated my project, copied the files in, redone everything as all tutorials / SE answes say and still nothing works. –  May 01 '18 at 09:54

1 Answers1

1

What a nightmare. It seems I have two JDK's installed on my system, and my IntelliJ project is setup to use JDK 9.0.4. My Linux system is defaulting to some other version.

So all I needed to type in the end was /opt/jdk-9.0.4/bin/java -jar JavaFXApp.jar.

Wasted two days.