1、maven配置jdk版本java
解決方案一:修改maven的配置(解壓目錄的conf\setting.xml文件)spring
<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>
idea中apache
解決方案二:默認settigs.xml文件路徑爲:c:\users\xxx.m2\settings.xml,只要把設置好的settings.xml文件複製到該目錄下windows
解決方案三:修改項目中的pom.xmlspringboot
配置1或者配置2均可以服務器
maven加載首先會加載項目而後纔會加載配置文件中配置
配置1.框架
配置2.maven
<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>
2、springboot配置jdk注意:
ide
若是springboot版本對應的不對就算再改jdk雖然編譯的時候都能正常,打包運行也都正常,可是在服務器上仍是會出現奇葩的事情。編碼
例如:
錯誤 本地機器上裝的jdk8,springboot用2.1.5RELEASE版本改爲jdk7的打包方式, 本地寫代碼用lambda表達式編譯不經過,可是若是服務器上是jdk7的環境,啓動就會報錯。本地不管怎樣都不會報錯。由於是jdk8環境。
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/springframework/boot/loader/JarLauncher : Unsupported major.minor version 52.0
正確 若是用springboot用1.5.9RELEASE版本改爲jdk7的打包方式,服務器上jdk7的運行環境就不會報錯。能夠正常啓動。
總結:
因此不管用什麼框架,必定要了解清楚再使用。