maven專案的JDK版本的版本配置或者指定JDK版本,最實用的修改settings.xml和pom.xml修改方法,可以解決eplise中的90%因為jdk相容的問題,
阿新 • • 發佈:2019-01-27
公司近期匯入了一個專案,新專案剛剛匯入就有很多錯誤,這也是java專案的一個通病,根本的原因還是java的jvm虛擬機器的問題,還有各種依賴包的問題,有些問題很明顯,有些問題非常不明顯
下面我就把一些應為jdk版本引起的問題記錄下,
錯誤1:Dynamic Web Module 3.0 requires Java 1.6 or newer.
錯誤2:One or more constraints have not been satisfied.
錯誤3:The project cannot be built until build path errors are resolved
錯誤4:Java compiler level does not match the version of the installed Java project facet.
解決方法一(修改settings.xml檔案):
開啟本地maven安裝目錄中的settings.xml檔案
例如:“E:\javatool\apache-maven-3.5.4\conf\settings.xml”
在檔案中的profiles標籤中(這裡很重要)加入如下程式碼,我這裡是JDK1.8,如果你是其他的版本,就需要修改成其他的版本jdk
<profile> <id>jdk-1.8</id> <activation> <activeByDefault>true</activeByDefault> <jdk>1.8</jdk> </activation> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> </properties> </profile>
如下圖:
解決方法二(修改pom.xml檔案):
這個方法是修改maven專案中的pom.xml檔案,這個比較靈活,多專案的情況下建議使用``
在pom.xml檔案中插入下面程式碼:
<!-- jdk版本1.8 --> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.2</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build>
心得:在解決除錯bug問題上需要思路是先要解決基礎環境的問題,往往基礎的環境的問題可以處理連帶的解決很多報錯的問題。