日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

常用Maven收集以及Maven技巧

發布時間:2023/11/27 生活经验 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 常用Maven收集以及Maven技巧 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.完整的Maven的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 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>org.me</groupId><artifactId>main</artifactId><version>2.0.0</version><packaging>jar</packaging><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version></dependency><!-- Apache Commons Lang --><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.3.2</version></dependency><!-- Apache Commons Collections --><dependency><groupId>org.apache.commons</groupId><artifactId>commons-collections4</artifactId><version>4.0</version></dependency>       <dependency><groupId>commons-collections</groupId><artifactId>commons-collections</artifactId><version>3.2.2</version></dependency><dependency><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId><version>1.2</version></dependency><dependency><groupId>org.apache.httpcomponents</groupId><artifactId>httpclient</artifactId><version>4.5.2</version></dependency><dependency><groupId>org.apache.httpcomponents</groupId><artifactId>httpcore</artifactId><version>4.4.4</version></dependency><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.4</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>1.7.18</version></dependency><dependency><groupId>org.codehaus.jackson</groupId><artifactId>jackson-mapper-asl</artifactId><version>1.9.13</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>4.2.5.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>4.2.5.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-beans</artifactId><version>4.2.5.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-aop</artifactId><version>4.2.5.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>4.2.5.RELEASE</version></dependency><dependency><groupId>cglib</groupId><artifactId>cglib-nodep</artifactId><version>3.2.0</version></dependency><dependency><groupId>org.aspectj</groupId><artifactId>aspectjweaver</artifactId><version>1.8.8</version></dependency><dependency><groupId>aopalliance</groupId><artifactId>aopalliance</artifactId><version>1.0</version></dependency>       </dependencies><build><plugins><plugin>  <artifactId>maven-assembly-plugin</artifactId>  <configuration>  <appendAssemblyId>false</appendAssemblyId>  <descriptorRefs>  <descriptorRef>jar-with-dependencies</descriptorRef>  </descriptorRefs>  <archive>  <manifest>  <mainClass>com.me.main.MainJFrame</mainClass>  </manifest>  </archive>  </configuration>  <executions>  <execution>  <id>make-assembly</id>  <phase>package</phase>  <goals>  <goal>assembly</goal>  </goals>  </execution>  </executions>  </plugin></plugins></build>
</project>



注意:

使用maven默認的package命令構建的jar包中只包括了工程自身的class文件,并沒有包括依賴的jar包。我們可以通過配置插件來對工程進行打包,pom具體配置如下:

            <plugin>  <artifactId>maven-assembly-plugin</artifactId>  <configuration>  <appendAssemblyId>false</appendAssemblyId>  <descriptorRefs>  <descriptorRef>jar-with-dependencies</descriptorRef>  </descriptorRefs>  <archive>  <manifest>  <mainClass>com.me.main.MainJFrame</mainClass>  </manifest>  </archive>  </configuration>  <executions>  <execution>  <id>make-assembly</id>  <phase>package</phase>  <goals>  <goal>assembly</goal>  </goals>  </execution>  </executions>  </plugin>


參考:使用maven插件對java工程進行打包


2.Maven模塊劃分



建立一個父模塊mavenprojects

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.hm</groupId><artifactId>mavenprojects</artifactId><version>1.0-SNAPSHOT</version><packaging>pom</packaging><modules><module>projectclient</module><module>projectserver</module></modules><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties>
</project>


建立2個子項目projectclient和projectserver


projectserver有一個類

public class NewT {public int add(int a, int b) {return a + b;}
}

projectclient需要依賴此項目

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.hm</groupId><artifactId>mavenprojects</artifactId><version>1.0-SNAPSHOT</version></parent><artifactId>projectclient</artifactId><packaging>jar</packaging><properties><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target></properties><dependencies>  <dependency>  <groupId>com.hm</groupId>  <artifactId>projectserver</artifactId>  <version>${project.version}</version>  </dependency>  </dependencies>
</project>


projectclient調用
package com.hm.projectclient;import com.hm.projectserver.NewT;public class NewApp {public static void main(String[] args) {NewT t = new NewT();System.out.println(t.add(1, 2));}
}

參考: Maven最佳實踐:劃分模塊

總結

以上是生活随笔為你收集整理的常用Maven收集以及Maven技巧的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。