Get the App
SLTechnology News&Howtos  ›  Development  › 

What is it like to write a bat script that compiles and executes java code with the next click of the cmd interface

Shulou Source: shulou.com Published: 2022-06-02 10:27:46 10月07日 Update

The preparation of cmd interface one-click compilation, execution of java code bat script is like, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.

This script is suitable for students who have just come into contact with java. Use jc instead of complex javac * .java + java main under the cmd interface:

Copy the content of the script into the txt text, modify the suffix to .bat, run it once to complete the configuration, and then type jc in the cmd interface to complete the compilation + execution.

Function: 1. Compile and execute the java file in the current directory

If you encounter multiple java files of the main function, you will be prompted and selected to execute

The bat code is as follows

@ echo off

If not exist% SystemRoot%\ system32\ choice.exe echo Sorry, the system lacks the necessary components to run the program and cannot continue & pause > nul&exit / b 1

If not exist% SystemRoot%\ jc.bat copy% 0% SystemRoot%\ jc.bat 1 > nul 2 > nul& echo configured successfully, using method jc & pause > nul&exit / b 0

Rem production date October 23,2015 xin3283@qq.com

Rem purpose: compile and execute java files in the current directory

Set jclog=%temp%\ javac.log

If exist jclog% 1 0 > jclog% 2 > nul

Javac * .java 2 >% jclog%

(for / f "skip=6 tokens=2 delims= files"% I in ('dir /-c% jclog%') do @ echo% I | findstr / v "directory") >% temp%\ jcSize.txt

Set / p size=nul

Set / a MainSum=MainSum-1

For / l%% ain (1JI% MainSum%) do (

Set mains%% aweed mains% aVug 0mu 6i!

)

If "% MainSum%" = = "0" (

Echo error: the main class cannot be found or cannot be loaded, please check the Main function

Exit / b 2

) else if "% MainSum%" = = "1" (

Java main1%

Exit / b 0

)

There are the following main functions in echo, select

For / l%% I in (1Jing 1J% MainSum%) do echo% ivy mains% ifu.java

Choice / c 123456789 / n

Java! main% errorlevel%!

Exit / b 0

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: Compile file interface script function directory code content help run select configure one-click complex clear successful sorry usage instructions function Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei macOS NVidia MariaDB MySQL