简体   繁体   English

在Java项目文件夹中包括run.bat和compile.bat有什么作用?

[英]Including run.bat and compile.bat in java project folder does what?

As part of a college Java course project I've been asked to include a compiler.bat and a run.bat file in the projects root folder. 作为大学Java课程项目的一部分,我被要求在项目的根文件夹中包含一个compiler.batrun.bat文件。

From attempts to get these to do anything, I can't get them to work on OSX 10.13 (High Sierra). 从尝试使它们做任何事情开始,我都无法使它们在OSX 10.13(高Sierra)上工作。

From reading Google, and SO results these seem to be windows relevant files only? 从阅读Google的结果来看,这些似乎只是与Windows相关的文件?

Am not sure about there relevance but they are a requirement of the project so I'd like to understand what's going on or required. 不确定是否相关,但是它们是项目的要求,因此我想了解正在进行或需要的内容。

// compiler.bat ( 0775 Permissions )
@echo off
javac "./App.java"
pause  


// run.bat ( 0775 Permissions )
@echo off
java "./App"
pause  

And both sit in the same directory, beside App.Java. 两者都位于App.Java旁边的同一目录中。

If you take a look at the compiler.bat , all it really does is call javac . 如果您看一下compiler.bat ,它真正要做的就是调用javac This is used to compile the App.java file, as described here . 这是用来编译App.java文件,描述在这里 It basically turns the written java code into a *.class file which contains the Java bytecode. 基本上,它将编写的Java代码转换为包含Java字节码的* .class文件。 This step is necessary for running any java program. 这是运行任何Java程序所必需的。 There are a lot of explanations on the java bytecode available, for example here . 关于Java字节码,有很多说明,例如here

run.bat is responsible for running the programm. run.bat负责运行程序。 It takes the compiled code and starts the program. 它采用编译后的代码并启动程序。

These to steps are necessary for running java programs, so they are for example also described here 这些到步骤对于运行Java程序是必需的,因此,例如在此处也对它们进行了描述

Of course you don't need to use *.bat files for this. 当然,您不需要为此使用* .bat文件。 You can just as well use the same command from your command line: 您也可以在命令行中使用相同的命令:

javac "./App.java"
java "./App"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM