2,把所有的jar目录编译、拷贝到/lib目录(包括maven的jar包和lib目录下的jar,以及编译的jar包)
3,把所有的启动脚本从工程根目录拷贝到/bin目录
4,把所有的配置文件从src/main/resources拷贝到/conf
pom.xml 配置
<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>test</groupId>
<artifactId>test.common</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>test.common</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 这里省略n行 -->
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<!-- 把src/main/resources目录下所有的文件拷贝到conf目录中 -->
<resource>
<directory>src/main/resources</directory>
<targetPath>${project.build.directory}/conf</targetPath>
</resource>
<!-- 把lib目录下所有的文件拷贝到lib目录中
(可能有些jar包没有办法在maven中找到,需要放在lib目录中) -->
<resource>
<directory>lib</directory>
<targetPath>${project.build.directory}/lib</targetPath>
</resource>
<!-- 把放在根目录下的脚本文件.sh,.bat拷贝到bin目录中 -->
<resource>
<directory>.</directory>
<includes>
<include>**/*.sh</include>
<include>**/*.bat</include>
</includes>
<targetPath>${project.build.directory}/bin</targetPath>
</resource>
</resources>
<plugins>
<!-- 用于编译的plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<fork>true</fork>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
<!-- 如果配置了JAVA_HOME,下面应该可以不用配 -->
<executable>C:\Program Files (x86)\Java\jdk1.8.0_91\bin\javac.exe</executable>
</configuration>
</plugin>
<!-- 用于生成jar包的plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<!-- 把生成的jar包放在lib目录下(和其他所有jar包一起) -->
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
<excludes>
<!-- 排除掉一些文件,不要放到jar包中,
这里是为了排除掉src/main/resources中的文件(它们应该放到conf目录)
这里只能指定要排除的目标文件,而不能指定源文件,虽然不够完美,但是基本能达到目的。 -->
<exclude>*.xml</exclude>
<exclude>*.properties</exclude>
</excludes>
</configuration>
</plugin>
<!-- 用于拷贝maven依赖的plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- 把依赖的所有maven jar包拷贝到lib目录中(这样所有的jar包都在lib目录中) -->
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- 用于拷贝resource的plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- 配置生成源代码jar的plugin -->
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<configuration>
<attach>true</attach>
<encoding>UTF-8</encoding>
<!-- 配置源代码jar文件的存放路径,和其他jar文件一起放在lib目录 -->
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
然后执行maven package打包。如果是eclipse,在Project Explorer->Run As –>Maven Build… –>在Goals中输入package,点Run进行编译。
<dependency><groupId>javabuilder</groupId>
<artifactId>javabuilder</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/javabuilder.jar
</systemPath>
</dependency>
像这样把包拷到项目里面,然后指定到项目下面就可以了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)