1. 添加jar到project
在project跟目录创建一个folder,起名叫lib,把所需要的jar都放在这里。菜单”Import –> File System”引入,或者直接copy到这个文件夹里。
2. 修改plug-in classpath
plugin editor –> Runtime tab –> Classpath section。
- “New…”将”.”添加进来,如果已经存在,就不用添加了。
- “Add…”将jar添加进来。
3. 检查jar是否include in the binary build
通常是正确的,只是检查下。build tab –> Binary Build section,看下新添加的jar是否打钩了。
4. 更新project classpath
project右键菜单 –> Plug-in Tools –> Update Classpath…, 选择plugin然后update。
project classpath更新后,通过maven依赖的jar会找不到了,再使用maven更新下project。右键菜单 –> Maven –> Update Project…,选择project然后update。
5. 自动copy到lib
使用dependency:copy-dependencies,将pom中所有的依赖jar,copy到指定目录,会递归的将jar依赖的其它jar也copy过去。这是合理的,因为jar所需要的依赖缺失的话,是无法运行的。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>verify</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
我将其设置在verify phase了,所以执行mvn verify就会触发copy行为。copy完后,再执行步骤2和步骤4。
总结
Plugin project没有必要enable maven特性,手动执行pom便可,然后update classpath。