Reputation: 97
I want to call a Java class from a batch file.
How can I do that?
Upvotes: 7
Views: 41320
Reputation: 169
If you are having:
Then:
use the parent dir of com e.g. c:\src
(the folder that contains the com package),
store the below commands in a batch file:
cd c:\\src
java -cp jar1;jar2; com.mycomp.util.Myclass
Execute the batch file to run the Java program.
Upvotes: 3
Reputation: 66
You can do the following:
Open a new Text File in Notepad.
Write the following lines of code, then saves it as "MyFile.bat"
(Note: Save it as a .BAT File)
@ECHO OFF
javac YourClass.java
java YourClass
Now double click the BAT file to execute your Java program.
Note: The BAT file and Java Class should be in the same directory.
Upvotes: 1
Reputation: 8771
@echo off
java -jar "C:\path_to_jar_directory\test.jar"
"C:\path_to_arguments\property.properties"
Upvotes: 0
Reputation: 470
@ECHO OFF
java -jar "Path/To/The/Jar/Whatever.jar"
I would recommend first jaring up your class(es) and providing a link to the jar.
Upvotes: 4
Reputation: 323
Just use this in ur .bat file
java -classpath folderName/example.jar; com.example.package.ExampleProgram
if you are placing the .bat file in the same folder with the jar, then its not necessary to mention the folderName
Upvotes: 1
Reputation: 79185
If you have compiled your .java
file, and have the .class
file, containing bytecode for your main
function, then just run:
java myclass
where myclass
is the module name (file has to be myclass.class
).
Upvotes: 2