在配置Maven工程,部署到tomcat服務器運行的過程中,遇到如下錯誤:
1 "Unsupported major.minor version 51.0 "
錯誤原因是由於maven所引用的jdk版本與 tomcat所引用的版本不一致導致的,解決方案如下:
1.修改maven的jdk版本為1.7:
a)在maven的setting文件中加入
在setting.xml文件中的profiles元素下添加如下profile元素 <profile> <id>jdk17</id> <activation> <activeByDefault>true</activeByDefault> <jdk>1.7</jdk> </activation> <properties> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> <maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion> </properties> </profile>
b)在項目的pom,xml文件中添加如下build元素
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins> </build>
c)myeclipse->windows->perference->找到maven->修改jdk版本 (可選)
2.修改tomcat的jdk版本:
MyEclipse->window->Servers->Tomcat->Tomcat7.x->JDK->改成1.7(與maven一致)
別忘了關注我的公眾號,當然,前提是你對Java, Scala, Python等技術經驗,以及編程日記,感興趣的話。