我用maven打包我的jar。我希望用它的内部文件结构制作一个名为sdk-issue-0.0.1-SNAPSHOT-distribution.jar的jar,如下所示,这样可以很好地工作当它被导入项目时。
sdk-issue-0.0.1-SNAPSHOT-distribution.jar
|--myJar.jar
|--lib
|--jackson.jar
|--httpclient.jar
但结果是它们被打包到一个名为sdk-issue-0.0.1-SNAPSHOT-distribution的不需要的文件夹中。因此结构是:
sdk-issue-0.0.1-SNAPSHOT-distribution.jar
|--sdk-issue-0.0.1-SNAPSHOT-distribution
|--myJar.jar
|--lib
|--jackson.jar
|--httpclient.jar
因此,当添加到项目中时,我无法导入它。
我的pom.xml使用了maven-assembly-plugin:
<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.yonyou</groupId>
<artifactId>sdk-issue</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sdk-issue</name>
<properties>
<junit.version>4.11</junit.version>
<gson.version>2.7</gson.version>
<httpcomponents.version>4.5</httpcomponents.version>
</properties>
<build>
<plugins>
<!-- 编译插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- jar打包相关插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<!-- The configuration of the plugin -->
<configuration>
<!-- Configuration of the archiver -->
<archive>
<!-- 生成的jar中,不要包含pom.xml和pom.properties这两个文件 -->
<addMavenDescriptor>false</addMavenDescriptor>
<!-- Manifest specific configuration -->
<manifest>
<!-- 是否要把第三方jar放到manifest的classpath中 -->
<addClasspath>true</addClasspath>
<!-- 生成的manifest中classpath的前缀,因为要把第三方jar放到lib目录下,所以classpath的前缀是lib/ -->
<classpathPrefix>lib/</classpathPrefix>
<!-- 应用的main class -->
</manifest>
</archive>
<!-- 过滤掉不希望包含在jar中的文件 -->
<excludes>
<exclude>assembly\assembly.xml</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<descriptors>
<descriptor>assembly\assembly.xml</descriptor>
</descriptors>
<!-- <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs> -->
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- httpclient,发送HTTP请求 -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpcomponents.version}</version>
</dependency>
<!-- gson,json转换工具 -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
<!-- jjwt,Java Web Token签名工具包 -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.6.0</version>
</dependency>
<!-- bcprov-jdk15on,PEM格式私钥证书读取工具类 -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.52</version>
</dependency>
</dependencies>
这里是assembly.xml:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>distribution</id>
<formats>
<format>jar</format>
</formats>
<!--<fileSets>
<fileSet>
<directory>${project.basedir}\src\main\resources</directory>
<outputDirectory>\</outputDirectory>
</fileSet>
<fileSet>
<directory>${project.basedir}\src\bin</directory>
<outputDirectory>\bin</outputDirectory>
</fileSet>
</fileSets>-->
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<!--
不使用项目的artifact,第三方jar不要解压,打包进zip文件的lib目录
-->
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>lib</outputDirectory>
<unpack>false</unpack>
</dependencySet>
</dependencySets> </assembly>
如何将它们从不需要的文件夹中取出,以便在导入项目时jar可以正常工作?