Use the Maven command to package the Java background code under Windows

1 JDK environment variable configuration

To configure JDK environment variables under Windows, follow the steps below:

First, make sure you have installed the JDK. You can download the latest version of JDK from Oracle official website and install it.

Open Control Panel, click System and Security, then click System.

Click Advanced System Settings on the left, and the System Properties dialog box will pop up.

In the System Properties dialog box, click the Environment Variables button to open the Environment Variables dialog box.

In the list of user variables or system variables, look for a variable named JAVA_HOME. If the variable does not exist, a new variable needs to be created.

Click the New button, enter JAVA_HOME in the variable name, and enter the JDK installation path in the variable value. For example: C:\Program Files\Java\jdk1.8.0_301.

In the list of system variables, find the variable named Path, and double-click to edit it.

In the Edit Environment Variable dialog box, click the New button and enter %JAVA_HOME%\bin. This will add the JDK's bin directory to the system's PATH environment variable.

Click OK to save all changes and close the Environment Variables dialog and System Properties dialog.

Restart the command line window or other application, try running the javac command in it, and you should be able to successfully compile the Java program.

In this way, you have successfully configured the environment variables of the JDK. Make sure the path and version number match your actual installation.

2 Maven environment variable configuration

To configure Maven environment variables under Windows, the following steps are required:

Download Maven: First, you need to download the latest version of Maven from the Maven official website (https://maven.apache.org/download.cgi). Choose the appropriate binary zip file for your operating system.

Extract Maven: Extract the downloaded zip file to the directory where you want to install Maven. You can choose to extract it anywhere, but it is recommended to choose a path that does not contain spaces or special characters.

Create the MAVEN_HOME environment variable: In Windows, right-click "This PC" (or "My Computer"), select "Properties", then click "Advanced system settings" on the left. In the pop-up window, click the "Environment Variables" button.

In System Variables, click the New button. Enter MAVEN_HOME in "Variable Name", and enter the installation path of Maven in "Variable Value" (for example: C:\apache-maven-3.8.2).

Update the Path environment variable: Find the Path variable in "System Variables", double-click to edit it. Add %MAVEN_HOME%\bin to the end of the variable value, making sure to separate each path with a semicolon.

Usually, the computer needs to be restarted.

Verify installation: Open a command prompt window (Win + R, enter cmd), run the following command to verify that Maven is installed successfully:

mvn -v

If the environment variables are configured successfully, you should be able to see the Maven version information.

Now, you have successfully configured Maven environment variables, and you can use Maven commands in any directory.

3 Maven command packaging

Enter cmd under the background project path first, and press Enter to enter the command line
insert image description here

3.1 Clear the previously packaged package

To clear previously opened packages, you can use the following command:

mvn clean

This command will clear the previously built object files and temporary files, including the class files generated by compilation, class files generated by testing, JAR files generated by packaging, etc. After executing this command, you can rebuild the project.

3.2 Direct packaging

To package using Maven, you can use the following command:

mvn package

This command will execute the default life cycle of the project, including compilation, testing, packaging and other processes. It compiles project source code and packages it into a distributable format, such as a JAR, WAR, or other type of archive, for deployment and use.

3.3 Skip unit tests for packaging

To skip unit tests for packaging with Maven, you can use the following command:

mvn package -Dmaven.test.skip=true

-Dmaven.test.skip=trueis a system property that tells Maven to skip executing unit tests by setting it to true. This option is usually used during the build process if you don't want to run tests, or a test environment is not available. Skipping tests can speed up builds.

Packing done!
insert image description here

Note that skipping tests may lead to failure to discover potential problems in the code, so it is recommended to ensure that all unit tests pass before the actual release.

Guess you like

Origin blog.csdn.net/weixin_46098577/article/details/131981016