问题:
当项目是maven项目时,因为jar通过pom管理,所以正常配置即可编译成功,但是有些时候项目需要引用内部部分jar,一般存放在WEB-INF/lib下,此时编译(执行compile或者其他命令)会报错,如下:
程序包com.xxx.dao不存在
xxx.java:[16,34] 找不到符号
解决方案:
配置pom.xml,使其编译时引用外部jar,配置如下:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
<!-- true:跳过测试 -->
<skip>true</skip>
<encoding>UTF-8</encoding>
<!-- 既用maven编译,又使用lib下的Jar包 时必须加上此配置 -->
<compilerArgs>
<!-- 参数名和参数值成对出现,即第一个是名,第二个是值 -->
<arg>-extdirs</arg>
<arg>${project.basedir}/src/main/webapp/WEB-INF/lib</arg>
</compilerArgs>
</configuration>
</plugin>
注意红色字体为新增配置。