In simple terms, the construction project is to compile, package, run, deploy, and perform other operations.
(1) preparation: Create a helloworld folder to store the project. There are two folders SRC and build in the root directory of the helloworld project, and SRC is the source code folder, build is used to place the files obtained after the project is built. The build folder contains the classes and Lib folders, And the classes is used to place the class files obtained by compiling java files in SRC, lib is used to place the jar packages generated or referenced by the build project.
(2) The code for creating helloworld. Java in helloworld is as follows:
Public class helloworld {
Public static void main (string [] ARGs ){
System. Out. println ("Hello world! ");
}
}
Compile the Java class in the doscommand line as follows:
First, switch the path to the project directory, and then call javac to compile the source file.
-Sourcepath SRC: Specifies the Java file to be compiled in the SRC folder;
-D Indicates placing the generated class file in the build \ Classes directory.
(3) generate jar:
When you package and generate a jar file, you need to provide the mainifest file. In this file, you can configure main-class, that is, class containing the main method, as the program portal for calling and executing this jar package, you can configure the information of other referenced class libraries and packages in this file.
Run the echo main-class: helloworld> manifest command to generate a manifest file and specify main-class o helloworld.
(4) run the project:
1. Execute the compiled Java class directly.
The CP parameter specifies the path of the helloworld class file.
2. Execute the JAR file in the doscommand line.