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?
7 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:
- Go to Run > External Tools > External tools Configurations
- Create an item under "Program"
Fill in:
Location:
/usr/bin/java(or the route to your java executable, in Linux you can find this by runningwhich javaon a terminal, in Windows you can usewhere javain command prompt)Working directory: The working directory for your jar program (usually its location)
Arguments:
-jar [path to your jar]
1 Comment
Ed Harrod
On windows you can use
where java instead of which java. If you want a JDK and not a JRE you need to look in the returned directories for 'bin/javac/`You could run the JAR with an "External Tool" launch configuration, found at Run > External Tools > External tools Configurations.
3 Comments
stevebot
:D thanks! I found it under Run > External Tools > External tools Configurations and then selected new Program.
Sanjay Jain
I also try this but it is giving me this issues Exception occurred executing command line. Cannot run program "D:\CapsON.jar" (in directory "D:\"): CreateProcess error=193, %1 is not a valid Win32 application
Nathaniel Verhaaren
@SanjayJain I got a similar error and found GermanK's answer helpful.

