這次一個項目用到maven編譯,我在本地開發的時候jar包都是放在WEB-INF/lib目錄下,通過
BuildPath將jar包導入,然后用MyEclipse中的:maven package命令打成war包,這個war包在tomcat下能正常運行,war包下是有lib下的jar包的。
通過IDEA自帶的運行能夠正常識別lib包下的jar,但是我要是通過maven profile實現多環境配置自動分離 則會出現“程序包xxx不存在的”錯誤
若該程序包是jdk自帶的程序包,請參照:解決maven編譯錯誤:程序包com.sun.xxx不存在
若該程序包是第三方的jar,解決方案是讓maven既加載maven庫中的jar包,又要加載本地WEB-INF/lib下的jar包。
現在終於解決問題了,方法是在pom.xml文件中添加一段配置:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.0</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> <compilerArguments> <extdirs>${project.basedir}/src/main/webapp/WEB-INF/lib</extdirs> </compilerArguments> </configuration> </plugin>