0

My project is an edited version of r0d0t's InfEncoder. You can find it on GitHub here.

What I modified is mainly support for Java 10, and that's fixing broken references and deprecated libraries. My current code is available here.

When I build the project in NetBeans it shows the following message:

"To run this application from the command line without Ant, try:

C:\Program Files\Java\jdk-10.0.1/bin/java -p C:\projects\InfEncoder-master\dist\InfEncoder.jar -m InfEncoder"

The command works fine and runs the code. However, what I am trying to do is to run the .jar file by double-clicking it or with the java -jar command, but the whole idea is to make r0d0t's original project run with Java 10.

EDIT: Since some deprecated libraries needed to be included in the project, NetBeans created a module-info class which states

module InfEncoder {
requires java.activation;
requires java.desktop;
requires java.base;
requires java.logging; }

This could be why the command -p has "InfEncoder" as the value. When running the project the entry module needs to be the one with referenced libraries in module-info. I have confirmed this by putting InfFrame instead of InfEncoder in the module-info class and the command that netbeans gives changes the entry module.

Emil Gajšak
  • 53
  • 1
  • 7
  • As many people I'm not willing to visit an unknown google drive. So I can't see the code. How are you bilding your jar? Do you use maven? If you do you should have a look at the assembly or shade plugin. If not you could probably use an "export as runnable jar" (or similar) routine of your IDE. – DrHopfen Jul 10 '18 at 12:02
  • The code is now on GitHub, rather than google drive. I am building my jar in Netbeans, without maven. I am quite new and am not aware of an "export as runnable jar" option in Netbeans – Emil Gajšak Jul 10 '18 at 15:09
  • Probably this could be useful: https://stackoverflow.com/questions/602537/producing-executable-jar-in-netbeans – DrHopfen Jul 11 '18 at 08:03

1 Answers1

0

To be able to run a Java application from a jar using the java -jar command or by double-clicking the jar, the jar's META-INF/MANIFEST file has to contain a Main-Class attribute, e.g.

Main-Class: com.my.App

if com.my.App is the fully qualified name of the class containing the application's main method.

Thomas Behr
  • 761
  • 4
  • 10
  • Thanks for trying to help. My manifest looks like this: `Manifest-Version: 1.0 Ant-Version: Apache Ant 1.10.1 Created-By: 10.0.1+10 ("Oracle Corporation") Main-Class: infencoder.InfFrame Class-Path: .lib/*` I am positive that InfFrame is my main class (it contains the main method). – Emil Gajšak Jul 10 '18 at 15:17
  • The `Class-Path: .lib/*` entry is not correct. `Class-Path` does not support wildcards, see (https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html). Moreover, is there really a `.lib` directory? It is kind of unusual to prefix library directories with a dot. By the way, what **does** happen if you run the application from command line using the `java -jar` command? – Thomas Behr Jul 10 '18 at 15:23
  • Okay, I have checked if commenting out the incorrect line would help, and I came to a conclusion that the changes I make to the manifest don't apply after I build the project. When I do compile it with java -jar it brings up errors of undefined classes that i have included in the lib folder. The errors do not show up when using the java -p -m command, though. – Emil Gajšak Jul 10 '18 at 18:36
  • Maybe that is because (according to documentation) you are using the `-p` option wrong: its argument should be a list of **directories**. I guess the JVM is lenient, ignores the fact that you are specifying a file, and just uses the `C:\projects\InfEncoder-master\dist` as search path (which would explain why it is working if your `lib` directory is a subdirectory of `dist`. – Thomas Behr Jul 11 '18 at 08:40
  • `lib` is not a subdirectory of `dist`, that I am sure of. The command itself is presented in the NetBeans compiler, so I assumed it didn't have any errors. Isn't `-p` the command to specify where the module to be loaded with `-m` is? My guess is it reads the .jar file just like a directory and loads the module "InfEncoder" from it. – Emil Gajšak Jul 11 '18 at 10:32