Environment:
jdk1.8,cmd,notepad++
To create a Java project test, create a folder:
Src
Classes
Lib
Description
src placement. java files
Classes placing the. class file
Lib-dependent jar packages required for project placement
Open CMD,CD to test,
Javac
1 javac-d. \classes-classpath. \lib\x1.jar;. \lib\x2.jar, ... \src\*.java
Description
-D. \classes specifies that the compiled classes file is placed in the current folder classes
. \src\*.java all Java files in the current folder
-classpath. \lib\x1.jar;x2.jar; Specifies the location of the dependent jar package, separated by semicolons (;). Separated by a colon (:) under Linux
Java
1 java-classpath. \classes;. \lib\x1.jar;. \lib\x2.jar; mainclassname
Description
-classpath. \classes;. \lib\x1.jar;x2.jar; Specify the location of the class file that you want to participate in running (including the dependent Jar package)
Mainclassname specifying the fully qualified name of the main class
Jar
CD to Classes folder,
1 jar-cvf Xx.jar. \*
After generating Xx.jar, open with compression software, modify the Manifest.mf file in the Meta-inf folder
Add two properties:
Main-class and Class-path
MAIN-CLASS Specifies the program's entry class, which is the class where the main function resides
CLASS-PATH specifies where the program relies on the jar package, with multiple jar spaces separated
Note the last line of the MANIFEST.MF file is empty. Otherwise, it will report java.lang.NoClassDefFoundError and other errors, which is equivalent to not searching the specified jar package.
1 manifest-version:1.0 2 created-by:1.8.0_172 (Oracle Corporation) 3 Main-class: The fully qualified name of the main class 4 Class-path:. /lib/xxx1.jar. /lib/xxx2.jar
Run the jar package
1 Java-jar Xx.jar
Take an example of MyBatis's automatic generation of SQL map for an experiment:
1 javac-d. \classes-classpath. \lib\mybatis-3.2.3.jar;. \lib\mybatis-generator-core-1.3.2.jar;. \lib\mysql-connector-java-5.1.28-bin.jar;. \lib\log4j-1.2.16.jar. \src\*.java
1 java-classpath. \classes;. \lib\mybatis-3.2.3.jar;. \lib\mybatis-generator-core-1.3.2.jar;. \lib\mysql-connector-java-5.1.28-bin.jar;. \lib\log4j-1.2.16.jar Generatorsqlmap
Operating Procedures and results:
Jar
Execution process and Results
Note
You must first create the SRC folder, otherwise you will not see the results.
If the targetproject attribute can be configured to No, then the SRC folder will be created automatically.
Reference article:
73881568
5009436
7786526
Https://www.cnblogs.com/xiazdong/p/3216220.html
Java----> Manually compile Java projects