Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a jar file in Eclipse

Tags:

java

eclipse

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?

like image 483
stevebot Avatar asked Dec 22 '10 01:12

stevebot


People also ask

How do I run 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 …]

How do I test a JAR file in Eclipse?

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..


1 Answers

You cannot directly execute a jar file. Instead, you need to run it using the java -jar command. In order to do that you:

  1. Go to Run > External Tools > External tools Configurations
  2. Create an item under "Program"
  3. 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]

like image 107
GermanK Avatar answered Sep 30 '22 19:09

GermanK