BAT Batch Compilation execution Java

Source: Internet
Author: User

While there are powerful IDE tools such as Eclipse, it is sometimes unavoidable to use the command line to manually compile and execute Java programs,

Recently I have encountered such a problem, suddenly feel the compilation and execution of the name of the Java or class file, such a good trouble,

Happen to have just learned the next DOS system and batch processing, so you want to write a batch. bat, come on easy,

Although not complex, but the first batch processing or is stumped by some problems, but the Huang Tian, eventually wrote out:


Copy the following two sections of code, open Notepad, paste it, and save it as a file with the suffix: ". bat",

Then put these two. bat files anywhere on your computer, such as on your desktop (recommended on your desktop),


When you need to manually compile and execute Java later, drag the selected Java file onto the Myjavac.bat file,

This assumes that I save the first piece of code in order to Myjavac.bat file, the same myjava.bat,

The generated class file is automatically compiled into the directory where the Java file is located,


Then select the class file you want to execute and drag it onto the Myjava.bat file, and it will be executed in bulk,


Both of these applets support up to 9 Java or class files simultaneously compiled and executed,

Originally intended to be compiled and executed together with it, but think about it, or so separate better,


Here's the code:


Batch Compile Myjavac:

@echo offecho.for%%i in (% 1%2%3%4%5%6%7%8%9) do (%%~di && cd%%~dpi && javac%%i && if%e Rrorlevel%==0 echo%%~nxi compilation completed) Echo.pause

Batch execution Myjava:

@echo offecho.for%%i in (% 1%2%3%4%5%6%7%8%9) does (%%~di && CD%%~dpi && start call Java%%~ni) Ech O.pause


BAT Batch Compilation execution Java

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.