1. 程式人生 > >maven工程中引入本地jar包並打包進war包裡面的方法

maven工程中引入本地jar包並打包進war包裡面的方法

首先需要說明的是,這種方法是很不可取的,因為Maven是用來團隊合作,以及釋出開原始碼的。而使用本地jar包,則使得Maven喪失了這部分的優點。不過有些jar包不再maven庫裡,然後就不得不想辦法想引用其中的一些jar包。
注意jar包存放的位置,一般是webapp/WEB-INFO/lib

<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/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.sunyainfo.sa_asset</groupId>
	<artifactId>sa_asset</artifactId>
	<packaging>war</packaging>
	<version>1.0-SNAPSHOT</version>
	<name>sa_asset Maven Webapp</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<spring.version>4.3.9.RELEASE</spring.version>
		<spring.data.jpa.version>1.4.3.RELEASE</spring.data.jpa.version>
		<maven.compiler.source>1.8</maven.compiler.source>
		<maven.compiler.target>1.8</maven.compiler.target>
	</properties>

	<!--正常引入maven庫的包 -->
	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>1.7.5</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>${spring.version}</version>
		</dependency>
		</dependency>
	</dependencies>


	<build>
		<finalName>sa_asset</finalName>

		<resources>
			<!--表示把java目錄下的有關xml檔案,properties檔案編譯/打包的時候放在resource目錄下 -->
			<resource>
				<directory>${basedir}/src/main/java</directory>
				<includes>
					<include>**/*.properties</include>
					<include>**/*.xml</include>
				</includes>
			</resource>
			<resource>
				<directory>${basedir}/src/main/resources</directory>
			</resource>
		</resources>

		<!--<!–引入本地jar包,就是plugins中的兩個plugin(不知道哪個起作用,最好都引入)–> -->
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.3.2</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
					<encoding>UTF-8</encoding>
					<compilerArguments>
						<extdirs>src\main\webapp\WEB-INF\lib</extdirs>
					</compilerArguments>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<configuration>
					<webResources>
						<resource>
							<directory>${project.basedir}/lib</directory>
							<targetPath>WEB-INF/lib</targetPath>
							<filtering>true</filtering>
							<includes>
								<include>**/*.jar</include>
							</includes>
						</resource>
					</webResources>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>