Default Manifest. Run class in Jar file In this post, We will learn how to run a Jar file from command prompt with main method and without main method. This is very useful in unix environment to run the jobs in nohup mode. But, now we will be focusing running jar file in windows operating system. If the class is not in a package then simply java -cp myJavaJar. If you are not within the directory where myJavaJar.
Here, flag cp is to set the jar in the java class-path. I want to be able to run each one of those as per the need. Connect and share knowledge within a single location that is structured and easy to search. If you have a jar file called myJar. I thought it would be to go into the directory and say java -cp myJar. Any help would be appreciated. The Documentation gives the following example:. To run a Runnable jar you can use java -jar fileName. Simple jar file that does not contain a manifest file so you simply run your main class by giving its path java -cp.
Assuming you are in the directory where myJar. A fully qualified path is preferred here as well. This is the right way to execute a. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Run class in Jar file Ask Question. Asked 10 years, 5 months ago. Active 3 years, 2 months ago.
Viewed k times. Improve this question. Unfortunately you need to spell out each jar in the manifest not a biggie as you only do once, and you can use a script to build the file or use a build tool like ANT or Maven or Gradle. And the reference has to be a relative or absolute directory to where you run the java -jar MyJar. HOW TO? When you specify -jar then the -cp parameter will be ignored.
From the documentation : When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.
App is the fully qualified name of the class from the JAR that has the main String[] method The jar and dependent jar should have execute permissions. You can do these in unix shell: java -cp MyJar. Main You can do these in windows powershell: java -cp "MyJar.
0コメント