Maven 打jar包配置
阿新 • • 發佈:2019-01-27
1.修改pom.xml增加如下內容
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <version>2.4</version>
- <configuration>
- <archive>
- <manifest>
-
<
- <classpathPrefix>lib/</classpathPrefix>
- <mainClass>com.sysware.HelloWorld</mainClass>
- </manifest>
- </archive>
- </configuration>
- </plugin>
執行mvn clean package即可
2.在pom.xml增加如下內容
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-assembly-plugin</artifactId>
- <version>2.3</version>
- <configuration>
- <appendAssemblyId>false</appendAssemblyId>
-
<
- <descriptorRef>jar-with-dependencies</descriptorRef>
- </descriptorRefs>
- <archive>
- <manifest>
- <mainClass>com.juvenxu.mvnbook.helloworld.HelloWorld</mainClass>
- </manifest>
- </archive>
- </configuration>
- <executions>
- <execution>
- <id>make-assembly</id>
- <phase>package</phase>
- <goals>
- <goal>assembly</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
3.
- <build>
- <finalName>...</finalName>
- <sourceDirectory>src/main/java</sourceDirectory>
- <resources>
- <!-- 控制資原始檔的拷貝 -->
- <resource>
- <directory>src/main/resources</directory>
- <targetPath>${project.build.directory}</targetPath>
- </resource>
- </resources>
- <plugins>
- <!-- 設定原始檔編碼方式 -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <defaultLibBundleDir>lib</defaultLibBundleDir>
- <source>1.6</source>
- <target>1.6</target>
- <encoding>UTF-8</encoding>
- </configuration>
- </plugin>
- <!-- 打包jar檔案時,配置manifest檔案,加入lib包的jar依賴 -->
- <plugin>