call java class in batch file

2020-03-21 05:36发布

i want to call the java class in batch file. how can i call. can tell me any commands which call the class file

Thanks Krishna

6条回答
够拽才男人
2楼-- · 2020-03-21 05:45


You can do the following:

  1. Open a new Text File in Notepad.
  2. Write the following lines of code, then saves it as "MyFile.bat" (Note we are saving as BAT File.

    @ECHO OFF
    javac YourClass.java
    java YourClass

  3. Now double click the BAT file to run, it should execute your java program.

  4. Note: The BAT file and Java Class should be in the same directory.


查看更多
祖国的老花朵
3楼-- · 2020-03-21 05:49

@echo off

java -jar "C:\path_to_jar_directory\test.jar" "C:\path_to_arguments\property.properties"

查看更多
We Are One
4楼-- · 2020-03-21 05:52

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

查看更多
狗以群分
5楼-- · 2020-03-21 05:58

if you are having a class Myclass with package name com.mycomp.util then you have to go to the parent dir of "com" for example "c:\src" is the folder that contains com package then

your command should be in the batch file

cd c:\src java -cp jar1;jar2; com.mycomp.util.Myclass

now call the batch file.

查看更多
迷人小祖宗
6楼-- · 2020-03-21 05:58

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

查看更多
干净又极端
7楼-- · 2020-03-21 06:06
@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.

查看更多
登录 后发表回答