非pom导入的额外Jar包, 在 maven clean install
的时候是会报错的, 程序包 *.*.* 不存在
, 需要配置 pom.xml
。
我们将额外Jar包放在一个统一的目录 ${dirs}
下面。
dependency
加上 <scope>system</scope>
以及 Jar包位置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <dependency> <groupId>${groupId}</groupId> <artifactId>${artifactId}</artifactId> <version>${version}</version> <scope>system</scope> <systemPath>${project.basedir}/${dirs}/target1.jar</systemPath> </dependency>
<dependency> <groupId>${groupId}</groupId> <artifactId>${artifactId}</artifactId> <version>${version}</version> <scope>system</scope> <systemPath>${project.basedir}/${dirs}/target2.jar</systemPath> </dependency>
|
build
时, 把Jar包加入 manifestEntries
- Class-Path
(我的配置文件将配置文件, lib, webApp等都打包在Jar包外)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
| <build> <plugins>
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>true</overWriteSnapshots> <excludeScope>provided</excludeScope> </configuration> </execution> </executions> </plugin>
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>${java.version}</source> <target>${java.version}</target> <compilerArgument>-proc:none</compilerArgument> <encoding>UTF-8</encoding> </configuration> </plugin>
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.6</version> <executions>
<execution> <id>copy-web</id> <phase>package</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <encoding>UTF-8</encoding> <outputDirectory>${project.build.directory}/webApp</outputDirectory> <resources> <resource> <directory>webApp</directory> </resource> </resources> </configuration> </execution>
<execution> <id>copy-conf</id> <phase>package</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <encoding>UTF-8</encoding> <outputDirectory>${project.build.directory}</outputDirectory> <resources> <resource> <directory>src/main/resources</directory> </resource> </resources> </configuration> </execution>
<execution> <id>copy-authFile</id> <phase>package</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <encoding>UTF-8</encoding> <outputDirectory>${project.build.directory}</outputDirectory> <resources> <resource> <directory>.</directory> <include>settings.txt</include> </resource> </resources> </configuration> </execution>
<execution> <id>copy-lib</id> <phase>package</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> <resources> <resource> <directory>${dirs}</directory> </resource> </resources> </configuration> </execution>
</executions> </plugin>
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.4</version> <configuration> <classesDirectory>target/classes/</classesDirectory> <archive> <addMavenDescriptor>false</addMavenDescriptor> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>${mainClass}</mainClass> </manifest> <manifestEntries> <Class-Path> lib/target1.jar lib/target2.jar </Class-Path> </manifestEntries> </archive> </configuration> </plugin> </plugins> </build>
|