当前位置: 代码迷 >> 综合 >> How to use maven wrapper manager a project
  详细解决方案

How to use maven wrapper manager a project

热度:58   发布时间:2023-12-14 23:22:37.0

In recent years, Spring boot is the favorite technology framework of many Java developers. Here, we have a very simple standard Spring boot project called heishan, as follows.

lwk@qwfys:~/Public/project/default/heishan$ tree -a
.
├── .gitignore
├── .mvn
│   └── wrapper
│       ├── MavenWrapperDownloader.java
│       ├── maven-wrapper.jar
│       └── maven-wrapper.properties
├── mvnw
├── mvnw.cmd
├── pom.xml
├── README.md
└── src├── main│   ├── java│   │   └── com│   │       └── qwfys│   │           └── sample│   │               └── heishan│   │                   └── HeishanApplication.java│   └── resources│       ├── application.properties│       ├── static│       └── templates└── test└── java└── com└── qwfys└── sample└── heishan└── HeishanApplicationTests.java18 directories, 11 files
lwk@qwfys:~/Public/project/default/heishan$

This is based on the directory structure of the project presented by the Linux command tree -a

lwk@qwfys:~/Public/project/default/heishan$ cat pom.xml 
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.5.0</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.qwfys.sample</groupId><artifactId>heishan</artifactId><version>0.0.1-SNAPSHOT</version><name>heishan</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
lwk@qwfys:~/Public/project/default/heishan$

Here is the content of the file pom.xml presented by the Linux command cat.

lwk@qwfys:~/Public/project/default/heishan$ cat src/main/java/com/qwfys/sample/heishan/HeishanApplication.java 
package com.qwfys.sample.heishan;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class HeishanApplication {
    public static void main(String[] args) {
    SpringApplication.run(HeishanApplication.class, args);}}
lwk@qwfys:~/Public/project/default/heishan$ cat src/main/resources/application.properties lwk@qwfys:~/Public/project/default/heishan$

Normally, we can start the project by executing the command mvn spring-boot:run in the command line terminal. Is there a way for our customers to run the project without worrying about how to configure the environment? In fact, yes, we can use maven wrapper.

Next, I will use maven wrapper to show you how to run it.

lwk@qwfys:~/Public/project/default/heishan$ ./mvnw spring-boot:run
[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------------< com.qwfys.sample:heishan >----------------------
[INFO] Building heishan 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] >>> spring-boot-maven-plugin:2.5.0:run (default-cli) > test-compile @ heishan >>>
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ heishan ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ heishan ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/lwk/Public/project/default/heishan/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ heishan ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory /home/lwk/Public/project/default/heishan/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ heishan ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/lwk/Public/project/default/heishan/target/test-classes
[INFO] 
[INFO] <<< spring-boot-maven-plugin:2.5.0:run (default-cli) < test-compile @ heishan <<<
[INFO] 
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.5.0:run (default-cli) @ heishan ---
[INFO] Attaching agents: [].   ____          _            __ _ _/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\\/  ___)| |_)| | | | | || (_| |  ) ) ) )' |____| .__|_| |_|_| |_\__, | / / / /=========|_|==============|___/=/_/_/_/:: Spring Boot :: (v2.5.0)2021-06-05 00:55:58.864 INFO 31996 --- [ restartedMain] c.q.sample.heishan.HeishanApplication : Starting HeishanApplication using Java 1.8.0_292 on qwfys with PID 31996 (/home/lwk/Public/project/default/heishan/target/classes started by lwk in /home/lwk/Public/project/default/heishan) 2021-06-05 00:55:58.866 INFO 31996 --- [ restartedMain] c.q.sample.heishan.HeishanApplication : No active profile set, falling back to default profiles: default 2021-06-05 00:55:58.905 INFO 31996 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable 2021-06-05 00:55:58.905 INFO 31996 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG' 2021-06-05 00:55:59.394 INFO 31996 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2021-06-05 00:55:59.399 INFO 31996 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2021-06-05 00:55:59.400 INFO 31996 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.46] 2021-06-05 00:55:59.426 INFO 31996 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2021-06-05 00:55:59.426 INFO 31996 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 521 ms 2021-06-05 00:55:59.609 INFO 31996 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729 2021-06-05 00:55:59.625 INFO 31996 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-06-05 00:55:59.632  INFO 31996 --- [  restartedMain] c.q.sample.heishan.HeishanApplication    : Started HeishanApplication in 0.991 seconds (JVM running for 1.225)
2021-06-05 00:55:59.633  INFO 31996 --- [  restartedMain] o.s.b.a.ApplicationAvailabilityBean      : Application availability state LivenessState changed to CORRECT
2021-06-05 00:55:59.634  INFO 31996 --- [  restartedMain] o.s.b.a.ApplicationAvailabilityBean      : Application availability state ReadinessState changed to ACCEPTING_TRAFFIC

Is it convenient to do so? Friends, what do you think?

  相关解决方案