Here we introduce the jar package method and the war package method.
Package the project
1. Open the command window in the directory where the project pom.xml is located. To open the command line window, press shift and right-click the mouse. this option.
2. Execute the command mvn package
to generate a jar package or war package in the target directory. Execute mvn clean
to delete the original target folder. .
3. Configuration of the generated package type. Whether to generate a jar package or a war package is determined by the configuration in pom.xml.
<packaging>jar</packaging> //生成jar包 <packaging>war</packaging> //生成war包
Online video tutorial sharing: java free video tutorial
The first jar package method
Comparison of this method It's simple, just install the java runtime environment. The method is:
Start the project command:
java -jar jar包全名(路径名+文件名)
The project will be started successfully, just access it directly in the address bar.
Note:
The default port number is 8080, which can be changed. For example, in the springboot project, configure server.port=80
in the configuration file application.properties. Change the port number to 80. This port number does not need to be written in the address bar. For example: localhost is equivalent to localhost: 80
The second is the war method
This method needs to be run in tomcat
will generate The war package is placed in the webapps directory of tomcat. At this time, the name of the war must be ROOT.war (it is best to delete the original ROOT folder, because a ROOT folder will be generated after starting tomcat) so that access will be normal. Otherwise, a 404 error will be reported.
If the name of war is not ROOT.war, then you need to change it in the tomcat configuration.
Open conf/server.xml and add a line in it, and add
<Context path="" debug="0" docBase="war包的名字,没有后缀名" reloadable="true"/>
in the Host tag. The port number in this method is subject to the one configured in the project and tomcat.
Recommended java related articles and tutorials: Introduction to java language
The above is the detailed content of How to publish java project. For more information, please follow other related articles on the PHP Chinese website!