I tried to run a jar file by going to Run configurations and then creating a new Java App, but Eclipse wants me to give it a main class and reference to the project. Can't I just give Eclipse a jar file?
To run an application in a nonexecutable JAR file, we have to use -cp option instead of -jar. We'll use the -cp option (short for classpath) to specify the JAR file that contains the class file we want to execute: java -cp jar-file-name main-class-name [args …]
Simply add the library ( test. jar ) to the classpath (build path). If you see it in the package explorer and in your on project, right click and you should find some Add to build path..
You cannot directly execute a jar file. Instead, you need to run it using the java -jar
command. In order to do that you:
Fill in:
Location: /usr/bin/java
(or the route to your java executable, in Linux you can find this by running which java
on a terminal, in Windows you can use where java
in command prompt)
Working directory: The working directory for your jar program (usually its location)
Arguments: -jar [path to your jar]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With