Ubuntu16.04上安装Jdk1.8和Tomcat8
程序员文章站
2022-07-13 21:23:46
...
Ubuntu16.04安装Jdk1.8和Tomcat8问题处理
Ubuntu16.04上原本安装有jdk1.7版本,现在打算安装一个1.8版本,并安装Tomcat8,但是安装以后发现启动Tomcat时,始终报错:
org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.0.32 (Ubuntu)
org.apache.catalina.startup.VersionLoggerListener.log Server built: May 28 2018 17:21:29 UTC
org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.0.32.0
org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux
org.apache.catalina.startup.VersionLoggerListener.log OS Version: 4.4.0-128-generic
org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
org.apache.catalina.startup.VersionLoggerListener.log Java Home: /usr/lib/jvm/java-7-oracle/jre
org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.7.0_80-b15
org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /var/lib/tomcat8
org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /usr/share/tomcat8
org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/var/lib/tomcat8/conf/logging.properties
org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.awt.headless=true
org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xmx128m
org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -XX:+UseConcMarkSweepGC
org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.endorsed.dirs=/usr/share/tomcat8/endorsed
org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/var/lib/tomcat8
org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/share/tomcat8
org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/tmp/tomcat8-tomcat8-tmp
org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
org.apache.catalina.startup.Catalina.load Initialization processed in 628 ms
org.apache.catalina.core.StandardService.startInternal Starting service Catalina
org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.32 (Ubuntu)
[localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDescriptor Deploying configuration descriptor /etc/tomcat8/Catalina/localhost/examples.xml
[localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/examples]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:585)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1794)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoSuchMethodError: java.util.concurrent.ConcurrentHashMap.keySet()Ljava/util/concurrent/ConcurrentHashMap$KeySetView;
at org.apache.catalina.core.StandardContext.findParameters(StandardContext.java:3585)
at org.apache.catalina.core.StandardContext.mergeParameters(StandardContext.java:5418)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5247)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
从中可以看出Tomcat8使用的仍然是jdk1.7, 为何如此呢?
可能jdk1.7这个版本和Tomcat8版本不一致导致这个错误,需要更新到1.8试一下。
通过查看/etc/init.d/tomcat8 文件可以看到:
find_jdks()
{
for java_version in 9 8 7
do
for jvmdir in /usr/lib/jvm/java-${java_version}-openjdk-* \
/usr/lib/jvm/jdk-${java_version}-oracle-* \
/usr/lib/jvm/jre-${java_version}-oracle-* \
/usr/lib/jvm/java-${java_version}-oracle
do
if [ -d "${jvmdir}" ]
then
JDK_DIRS="${JDK_DIRS} ${jvmdir}"
fi
done
done
# Add the paths for the JVMs packaged by the older versions of java-package (<< 0.52 as in Wheezy and Trusty)
JDK_DIRS="${JDK_DIRS} /usr/lib/jvm/j2re1.7-oracle /usr/lib/jvm/j2sdk1.7-oracle"
}
默认按照这些路径来查找jdk,如果你安装时不是按照这个路径安装的,那就找不到。
# tar xzvf jdk-8u171-linux-x64.tar.gz -C /usr/lib/jvm/
# mv jdk1.8.0_171 java-8-oracle
然后修改环境变量,再次运行tomcat8: service tomcat8 restart
这次找到的是tomcat8,而且不再报错。
jdk是下载包文件安装,
tomcat8是通过源安装:
sudo apt-get install tomcat8 tomcat8-docs tomcat8-examples tomcat8-admin
没有错误后,看通过 127.0.0.1:8080 查看启动是否正常。
https://www.cnblogs.com/qvduoduo/p/6098020.html
https://www.cnblogs.com/EasonJim/p/7202844.html
上一篇: CentOS7上安装与配置Tomcat8与MySQL5.7
下一篇: Tomcat8配置SSL证书