LINUX.ORG.RU
ФорумAdmin

Не работает tomcat9 + java

 ,


0

1

Здравствуйте.
Помогите, пожалуйста разобраться в проблеме.
Имею написанный не мной сервлет на java. Мне необходимо развернуть его на сервере. На сервере - debian8. Сервлет не запускается.
Cуть проблемы, как я её понимаю: сервлет написан на java, версии выше, чем по-умолчанию установлена на сервере из репозиториев, поэтому сервлет не работает, а настройка других версий tomcat или java - не получается.

apt-get install tomcat8 java-common

http://localhost:8080/ работает,
http://localhost:8080/Mytest/Servlet.html страничка с кнопкой запуска скрипта, по нажатию кнопки выдаёт ошибку:
 Unsupported major.minor version 52.0

Которую я понимаю как несоответствие версий, спасибо гугл.

По моему пониманию, jdk1.8.0_121 это то, что мне нужно. скачиваю с офсайтаархив и распаковываю его в /opt/java8

Настраиваю так:
update-alternatives --install /usr/bin/java java /opt/java8/jre/bin/java 100
update-alternatives --install /usr/bin/javac javac /opt/java8/bin/javac 100

И выбираю нужную версию посредством:
update-alternatives --config java
update-alternatives --config javac


Добавляю файл /usr/share/tomcat8/bin/setenv.sh с таким содержимым:
JAVA_HOME=/opt/java8
CLASSPATH=/opt/javahlam/mysql-connector-java-5.1.40-bin.jar:/opt/javahlam/servlet-api.jar


При попытке запуска службы tomcat8 получаю такое в лог:
Jan 26, 2017 10:56:35 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat8/common/classes], exists: [false], isDirectory: [false], canRead: [false]
Jan 26, 2017 10:56:35 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat8/common], exists: [false], isDirectory: [false], canRead: [false]
Jan 26, 2017 10:56:35 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat8/server/classes], exists: [false], isDirectory: [false], canRead: [false]
Jan 26, 2017 10:56:35 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat8/server], exists: [false], isDirectory: [false], canRead: [false]
Jan 26, 2017 10:56:35 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat8/shared/classes], exists: [false], isDirectory: [false], canRead: [false]
Jan 26, 2017 10:56:35 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat8/shared], exists: [false], isDirectory: [false], canRead: [false]
Jan 26, 2017 10:56:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version: Apache Tomcat/8.0.14 (Debian)
Jan 26, 2017 10:56:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:   Jan 6 2017 09:21:22
Jan 26, 2017 10:56:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number:  8.0.14.0
Jan 26, 2017 10:56:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:        Linux
Jan 26, 2017 10:56:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:     3.16.0-4-amd64
Jan 26, 2017 10:56:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture:   amd64
Jan 26, 2017 10:56:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version:    1.8.0_121-b13
Jan 26, 2017 10:56:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor:     Oracle Corporation
Jan 26, 2017 10:56:36 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Jan 26, 2017 10:56:36 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Jan 26, 2017 10:56:36 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1371 ms
Jan 26, 2017 10:56:36 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jan 26, 2017 10:56:36 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.14 (Debian)
Jan 26, 2017 10:56:36 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /var/lib/tomcat8/webapps/Mytest.war
Jan 26, 2017 10:56:36 PM org.apache.tomcat.util.descriptor.DigesterFactory locationFor
WARNING: The XML schema [web-jsptaglibrary_1_1.dtd] could not be found. This is very likely to break XML validation if XML validation is enabled.
Jan 26, 2017 10:56:36 PM org.apache.tomcat.util.descriptor.DigesterFactory locationFor
WARNING: The XML schema [web-jsptaglibrary_1_2.dtd] could not be found. This is very likely to break XML validation if XML validation is enabled.
Jan 26, 2017 10:56:36 PM org.apache.tomcat.util.descriptor.DigesterFactory locationFor
WARNING: The XML schema [web-jsptaglibrary_2_0.xsd] could not be found. This is very likely to break XML validation if XML validation is enabled.
Jan 26, 2017 10:56:36 PM org.apache.tomcat.util.descriptor.DigesterFactory locationFor
WARNING: The XML schema [jsp_2_0.xsd] could not be found. This is very likely to break XML validation if XML validation is enabled.
Jan 26, 2017 10:56:36 PM org.apache.tomcat.util.descriptor.DigesterFactory locationFor
WARNING: The XML schema [web-jsptaglibrary_2_1.xsd] could not be found. This is very likely to break XML validation if XML validation is enabled.
Jan 26, 2017 10:56:36 PM org.apache.tomcat.util.descriptor.DigesterFactory locationFor
WARNING: The XML schema [jsp_2_1.xsd] could not be found. This is very likely to break XML validation if XML validation is enabled.
Jan 26, 2017 10:56:36 PM org.apache.tomcat.util.descriptor.DigesterFactory locationFor
WARNING: The XML schema [jsp_2_2.xsd] could not be found. This is very likely to break XML validation if XML validation is enabled.
Jan 26, 2017 10:56:36 PM org.apache.tomcat.util.descriptor.DigesterFactory locationFor
WARNING: The XML schema [web-app_3_1.xsd] could not be found. This is very likely to break XML validation if XML validation is enabled.
Jan 26, 2017 10:56:36 PM org.apache.tomcat.util.descriptor.DigesterFactory locationFor
WARNING: The XML schema [web-fragment_3_1.xsd] could not be found. This is very likely to break XML validation if XML validation is enabled.
Jan 26, 2017 10:56:36 PM org.apache.tomcat.util.descriptor.DigesterFactory locationFor
WARNING: The XML schema [web-common_3_1.xsd] could not be found. This is very likely to break XML validation if XML validation is enabled.
Jan 26, 2017 10:56:36 PM org.apache.tomcat.util.descriptor.DigesterFactory locationFor
WARNING: The XML schema [javaee_7.xsd] could not be found. This is very likely to break XML validation if XML validation is enabled.
Jan 26, 2017 10:56:36 PM org.apache.tomcat.util.descriptor.DigesterFactory locationFor
WARNING: The XML schema [jsp_2_3.xsd] could not be found. This is very likely to break XML validation if XML validation is enabled.
Jan 26, 2017 10:56:36 PM org.apache.tomcat.util.descriptor.DigesterFactory locationFor
WARNING: The XML schema [javaee_web_services_1_4.xsd] could not be found. This is very likely to break XML validation if XML validation is enabled.
Jan 26, 2017 10:56:36 PM org.apache.tomcat.util.descriptor.DigesterFactory locationFor
WARNING: The XML schema [javaee_web_services_client_1_4.xsd] could not be found. This is very likely to break XML validation if XML validation is enabled.
Jan 26, 2017 10:56:38 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Jan 26, 2017 10:56:38 PM org.apache.catalina.core.ContainerBase addChildInternal
SEVERE: ContainerBase.addChild: start: 
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/Mytest]]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
	at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:919)
	at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1703)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;
	at org.apache.tomcat.websocket.server.WsServerContainer.<init>(WsServerContainer.java:147)
	at org.apache.tomcat.websocket.server.WsSci.init(WsSci.java:131)
	at org.apache.tomcat.websocket.server.WsSci.onStartup(WsSci.java:47)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5245)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	... 10 more

Jan 26, 2017 10:56:38 PM org.apache.catalina.startup.HostConfig deployWAR
SEVERE: Error deploying web application archive /var/lib/tomcat8/webapps/Mytest.war
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/Mytest]]
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:727)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
	at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:919)
	at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1703)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

Jan 26, 2017 10:56:38 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deployment of web application archive /var/lib/tomcat8/webapps/Mytest.war has finished in 1,549 ms
Jan 26, 2017 10:56:38 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /var/lib/tomcat8/webapps/ROOT
Jan 26, 2017 10:56:39 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Jan 26, 2017 10:56:39 PM org.apache.catalina.core.ContainerBase addChildInternal
SEVERE: ContainerBase.addChild: start: 
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1071)
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1721)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;
	at org.apache.tomcat.websocket.server.WsServerContainer.<init>(WsServerContainer.java:147)
	at org.apache.tomcat.websocket.server.WsSci.init(WsSci.java:131)
	at org.apache.tomcat.websocket.server.WsSci.onStartup(WsSci.java:47)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5245)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	... 10 more

Jan 26, 2017 10:56:39 PM org.apache.catalina.startup.HostConfig deployDirectory
SEVERE: Error deploying web application directory /var/lib/tomcat8/webapps/ROOT
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:727)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1071)
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1721)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

Jan 26, 2017 10:56:39 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /var/lib/tomcat8/webapps/ROOT has finished in 672 ms
Jan 26, 2017 10:56:39 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Jan 26, 2017 10:56:39 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2436 ms


Помогите, пожалуйста, сообразить, как это всё разрулить.

У тебя в переменной CLASSPATH прописан servlet-api.jar не той версии (похоже, что более старой), которая используется в tomcat-е, в итоге tomcat использует не свою библиотеку servlet-api, а из CLASSPATH. Т. к. версии не совпадают, то и падают потроха tomcat-а.

Убери описание /opt/javahlam/servlet-api.jar из CLASSPATH.

ma1uta ★★★ ()
Ответ на: комментарий от Piter_prbg

Исходная ошибка вот эта:

Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;
По ошибке можно сказать следующее:

  • ошибка падает из потрохов tomcat-а, т. е. ошибка относится к самому tomcat-у, а не приложению;
  • ошибка связана с javax.servlet;
  • ошибка java.lang.NoSuchMethodError говорит о том, что не существует такого метода. Т. е. tomcat ожидает, что существует данный метод, а его нет. Такое очень часто бывает, когда идёт замена каких-нибудь библиотек.

Дальше смотрим на окружение и замечаем, что в переменной CLASSPATH идёт замена servlet-api.jar. Следовательно, ошибка скорее всего в этом.

ma1uta ★★★ ()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.