這個問題糾結了一天,在另外一個電腦是正常的,但是從服務器下載下來到另外一個電腦的時候卻出現了如下圖問題
看到javac大家都會想到是編譯出現問題,而本地的配置如下圖所示:
看着配置都是一致的,會是哪里的問題呢?經網上咨詢有個大神說是可能是maven沒有配置指定的jdk原因,原因如下:
maven是個項目管理工具,如果我們不告訴它我們的代碼要使用什么樣的jdk版本編譯的話,它就會用maven-compiler-plugin默認的jdk版本來進行處理,這樣就容易出現版本不匹配的問題,以至於可能導致編譯不通過的問題。為了處理這一種情況的出現,在構建maven項目的時候,我習慣性第一步就是配置maven-compiler-plugin插件。解決辦法:
在pom.xml中指定使用的版本 1 <build>
2 <plugins> 3 <plugin> 4 <groupId>org.apache.maven.plugins</groupId> 5 <artifactId>maven-compiler-plugin</artifactId>
<!-- 使用3.5.1也是正確 不知道為啥 如果是3.0就是錯誤的,但是maven里面也有3.0的版本,可能跟我電腦安裝的maven版本有關,本地按照maven版本為3.0.5 -->
6 <version>3.1</version> 7 <configuration> 8 <defaultLibBundleDir>lib</defaultLibBundleDir> 9 指定高版本的源碼和編譯后的字節碼文件 10 <source>1.6</source> 11 <target>1.6</target> 12 <optimize>true</optimize> 13 <debug>true</debug> 14 <showDeprecation>true</showDeprecation> 15 <showWarnings>true</showWarnings> 16 <encoding>UTF-8</encoding> 17 </configuration> 18 </plugin> 19 20 </plugins> 21 </build>
經過指定后,電腦可以正常運行了。
問題2:
1 [WARNING] 2 [WARNING] Some problems were encountered while building the effective model for com.xxx.xxx:xxxx:jar:0.0.1-SNAPSHOT 3 [WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 72, column 12 4 [WARNING] 5 [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. 6 [WARNING] 7 [WARNING] For this reason, future Maven versions might no longer support building such malformed projects. 8 [WARNING]
對照官網用法:http://maven.apache.org/plugins/maven-compiler-plugin/usage.html
起初配置:
1 <plugins> 2 <plugin> 3 <artifactId>maven-compiler-plugin</artifactId> 4 <configuration> 5 <source>1.6</source> 6 <target>1.6</target> 7 <encoding>UTF-8</encoding> 8 </configuration> 9 </plugin> 10 </plugins>
該問題解決辦法是需要置頂maven版本,解決辦法:
1 <plugins> 2 <plugin> 3 <artifactId>maven-compiler-plugin</artifactId> 4 <version>3.0</version> 5 <configuration> 6 <source>1.6</source> 7 <target>1.6</target> 8 <encoding>UTF-8</encoding> 9 </configuration> 10 </plugin> 11 </plugins>