Reputation: 27
I thoroughly checked this one, and the standard answers aren't working for me.
Whenever I try to execute a jar file from cmd prompt, instead of opening the jar file it opens a new window of Dr. Java.
I've used DrJava's "Create custom drjava jar" to create a jar file called "TestJar.jar", including:
Manifest.txt:
Main-Class: com.package.name.TestJar Class-Path: algs4.jar
TestJar.java:
public class TestJar
{
public static void main(String[] args)
{
System.out.println("Hello");
StdOut.println("hello StdOut");
}
}
I type this in the cmd prompt:
java -jar TestJar.jar
And DrJava opens a new window. Any ideas? I've tried creating the jar file from cmd prompt but all commands I type starting with "jar" get this error:
'jar' is not recognized as an internal or external command, operable program or batch file.
Any help would be greatly appreciated...I'm pretty new to Java.
Upvotes: 1
Views: 6198
Reputation: 121881
1) To run your test jar from a Windows command:
a) Make sure Java is installed on your PC
b) Set your %JAVA_HOME% (EX: set JAVA_HOME=c:\Program files\java\jre7)
c) Update your %PATH% (EX: PATH=c:\Program files\java\jre7\bin;%PATH%)
d) Invoke program with "java -jar JARFILE MAIN-CLASS (EX: java -jar TestJar.jar TestJar)
2) To run DrJava .jar on Windows, I would just double-click on the .jar file from Windows Explorer
3) To test and debug your program, I would just use DrJava (instead of from the command line).
4) You do NOT need "jar.exe" installed to run a .jar file. You only need it to view, modify or create a .jar. jar.exe comes with the Java JDK.
5) I suspect you probably WILL need the Java JDK to build or debug any programs with DrJava, however.
Here's a good link on running .jar files from Windows, if you need more help:
Upvotes: 0
Reputation: 29974
Java determines the location of the main
function using a manifest. If you unzip your jar file, you'll see the manifest file in a META-INF folder. (A jar file is just a zip file with a different extension and some specific files inside.)
You'll need an entry like this in your manifest:
Main-Class: packagename.classname
See here for more details about setting the location of main
.
To control the manifest in Dr. Java, I think you will need to create a custom manifest. This source provides these instructions:
For more control over the properties of the jar, you may enter a custom manifest by selecting "Custom Manifest" and pressing the "Edit Manifest" button.
Upvotes: 0
Reputation: 7463
The problem you're having is that the jar
program is not in your %PATH%
. You may find this answer helpful.
Upvotes: 1