maven jar打包 集合
阿新 • • 發佈:2018-12-14
<!--控制該專案JDK版本 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.7.0</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> <!-- 打出jar包原始碼sources --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.1.2</version> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <!-- 打出無/有依賴的jar --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <configuration> <appendAssemblyId>false</appendAssemblyId> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <!-- 這部分可有可無,加上的話則直接生成可執行jar包 --> <archive> <manifest> <mainClass>com.demon</mainClass> </manifest> </archive> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>assembly</goal> </goals> </execution> </executions> </plugin> 注:jar-with-dependencies結尾的表示含有依賴的jar <!-- 安裝第三方的jar,即無法遠端倉庫下載的jar --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-install-plugin</artifactId> <version>2.5.2</version> <executions> <execution> <id>install-external</id> <phase>clean</phase> <configuration> <file>${basedir}/src/lib/demon-0.0.1.jar</file> <repositoryLayout>default</repositoryLayout> <groupId>com.demon</groupId> <artifactId>demon</artifactId> <version>0.0.1</version> <packaging>jar</packaging> <generatePom>true</generatePom> </configuration> <goals> <goal>install-file</goal> </goals> </execution> </executions> </plugin>
然後 Maven->Update Project ;然後在dependencies中即可如平常一樣新增依賴即可
<dependency> <groupId>com.demon</groupId> <artifactId>demon</artifactId> <version>0.0.1</version> </dependency>