标签:
网易蜂巢是网易推出的一个基于docker容器技术的云服务,最近需要用到网易蜂巢的容器。
可以直接用支持ssh连接的终端连到蜂巢
ssh -i id_rsa root@106.2.61.90
蜂巢用的是debian系统
root@sxplus-170598-2252272e-hl3nx:~# cat /etc/issue Debian GNU/Linux 7 \n \l
将项目从github克隆到蜂巢
git clone https://github.com/scarlettxu/restaurant.git
因为蜂巢没有publickey,所以用https协议
编译打包项目
mvn package
将项目包拷贝到tomcat
cp *.war /var/lib/tomcat7/webapps
在浏览器访问发布的服务
http://106.2.61.90:8080/restaurant/noodles
出现了如下错误
type Exception report message com/sx/NoodlesServlet : Unsupported major.minor version 51.0 (unable to load class com.sx.NoodlesServlet) description The server encountered an internal error (com/sx/NoodlesServlet : Unsupported major.minor version 51.0 (unable to load class com.sx.NoodlesServlet)) that prevented it from fulfilling this request. exception java.lang.UnsupportedClassVersionError: com/sx/NoodlesServlet : Unsupported major.minor version 51.0 (unable to load class com.sx.NoodlesServlet) org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2905) org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1170) org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678) org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:461) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1003) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579) org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) java.lang.Thread.run(Thread.java:701) note The full stack trace of the root cause is available in the Apache Tomcat/7.0.28 logs.
这个由于编译项目所用的java版本和运行是用的java版本不同
maven打包时所用的java版本
root@sxplus-170598-2252272e-hl3nx:/usr/lib/jvm/default-java/jre# mvn -version Apache Maven 3.0.4 Maven home: /usr/share/maven Java version: 1.7.0_95, vendor: Oracle Corporation Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre Default locale: en_US, platform encoding: ANSI_X3.4-1968 OS name: "linux", version: "3.18.20-nce-amd64", arch: "amd64", family: "unix"
tomcat运行用的default java
root@sxplus-170598-2252272e-hl3nx:/usr/lib/jvm/default-java/jre# ps -ef|grep tomcat root 1 0 0 10:27 ? 00:00:00 /bin/sh -c /etc/init.d/tomcat7 start && /etc/init.d/mysql start && /usr/sbin/sshd -D tomcat7 1601 1 2 11:20 ? 00:00:03 /usr/lib/jvm/default-java/bin/java -Djava.util.logging.config.file=/var/lib/tomcat7/conf/logging.properties -Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/share/tomcat7/endorsed -classpath /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar -Dcatalina.base=/var/lib/tomcat7 -Dcatalina.home=/usr/share/tomcat7 -Djava.io.tmpdir=/tmp/tomcat7-tomcat7-tmp org.apache.catalina.startup.Bootstrap start root 1643 483 0 11:22 pts/0 00:00:00 grep tomcat
default java 版本
root@sxplus-170598-2252272e-hl3nx:/# java -version java version "1.6.0_38" OpenJDK Runtime Environment (IcedTea6 1.13.10) (6b38-1.13.10-1~deb7u1) OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)
查看安装的所有java版本和default版本
root@sxplus-170598-2252272e-hl3nx:/usr/lib/jvm/default-java/jre# update-alternatives --display java java - auto mode link currently points to /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java - priority 1061 slave java.1.gz: /usr/lib/jvm/java-6-openjdk-amd64/jre/man/man1/java.1.gz /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java - priority 1051 slave java.1.gz: /usr/lib/jvm/java-7-openjdk-amd64/jre/man/man1/java.1.gz Current ‘best‘ version is ‘/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java‘.
更改default java版本
root@sxplus-170598-2252272e-hl3nx:/usr/lib/jvm/default-java/jre# update-alternatives --config java There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 auto mode 1 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode 2 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1051 manual mode Press enter to keep the current choice[*], or type selection number: 2 update-alternatives: using /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in manual mode
更改后的java版本
root@sxplus-170598-2252272e-hl3nx:/usr/lib/jvm/default-java/jre# java -version java version "1.7.0_95" OpenJDK Runtime Environment (IcedTea 2.6.4) (7u95-2.6.4-1~deb7u1) OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)
这还没有解决问题,最后是更改了项目里面的pom.xml里面的编译的版本,从1.6改为1.7,才解决了问题
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
标签:
原文地址:http://www.cnblogs.com/scarlettxu/p/5454408.html