Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report