Maven打war包时,添加本地jar包
1、在项目根目录中新建lib文件夹,添加jar包
2.在pom.xml文件中添加dependency
<dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc8</artifactId> <version>12.2.0.1</version> <scope>system</scope> <systemPath>${project.basedir}/lib/ojdbc8-12.2.0.1.jar</systemPath> </dependency>
${project.basedir}表示项目的根目录
在此配置后编码时可以引入jar包了,由于scope=system,打成war包时不会打进去
3.添加Maven插件,将jar包添加到war包中,在pom.xml文件中找到plugins标签,添加下面的代码
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.10</version> <executions> <execution> <id>copy-dependencies</id> <phase>compile</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/lib</outputDirectory> <includeScope>system</includeScope> </configuration> </execution> </executions> </plugin>
此时war中就包含了外部引入的jar包了