問題:每次右鍵項目名-maven->update project 時候,項目jdk版本變了,變回1.5版本或者其他版本
解決方案一:修改maven的配置(解壓目錄的conf\setting.xml文件)
<profile> <id>jdk1.6</id> <activation> <activeByDefault>true</activeByDefault> <jdk>1.6</jdk> </activation> <properties> <!-- want to use the Java 8 language features, Default 1.5 --> <maven.compiler.source>1.6</maven.compiler.source> <!-- want the compiled classes to be compatible with JVM 1.8, Default 1.5 --> <maven.compiler.target>1.6</maven.compiler.target> <!-- Version of the compiler to use, ex. "1.3", "1.5", if fork is set to true --> <maven.compiler.compilerVersion>1.6</maven.compiler.compilerVersion> </properties> </profile>
解決方案二:默認settigs.xml文件路徑為:c:\users\xxx\.m2\settings.xml,只要把設置好的settings.xml文件復制到該目錄下
解決方案三:修改項目中的pom.xml
<plugins> <!-- 指定maven插件編譯版本 1:maven:since2.0, 默認用jdk1.3來編譯,maven 3.x 貌似是默認用jdk 1.5。 2:windows默認使用GBK編碼,java項目經常編碼為utf8,也需要在compiler插件中指出,否則中文亂碼可能會出現編譯錯誤。 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <!-- since 2.0 --> <version>3.7.0</version> <configuration> <!-- use the Java 8 language features --> <source>1.8</source> <!-- want the compiled classes to be compatible with JVM 1.8 --> <target>1.8</target> <!-- The -encoding argument for the Java compiler. --> <encoding>UTF8</encoding> </configuration> </plugin> </plugins>