我一直在寻找8+的嵌入式tomcat版本,所以我从本教程中获得了一个版本:https://www.youtube.com/watch?v=VbXb73bU5N4。它在我的Windows上运行正常,现在在Linux上运行时出现了一些问题。我一直在寻找答案,却一无所获。如果class.path.java
是导致 文件名太长 的问题,我该怎么办?
错误消息:
Jul 30, 2018 6:18:09 PM org.apache.catalina.startup.Tomcat getWebappConfigFileFromJar
WARNING: Unable to determine web application context.xml /home/mateuszh/jdk1.8.0_181/jre/lib/charsets.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/deploy.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/cldrdata.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/dnsns.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/jaccess.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/jfxrt.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/localedata.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/nashorn.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/sunec.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/sunjce_provider.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/sunpkcs11.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/zipfs.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/javaws.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/jce.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/jfr.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/jfxswt.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/jsse.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/management-agent.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/plugin.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/resources.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/rt.jar:/home/mateuszh/IdeaProjects/embedded/target/classes:/home/mateuszh/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.0.28/tomcat-embed-core-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/embed/tomcat-embed-jasper/8.0.28/tomcat-embed-jasper-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/embed/tomcat-embed-el/8.0.28/tomcat-embed-el-8.0.28.jar:/home/mateuszh/.m2/repository/org/eclipse/jdt/core/compiler/ecj/4.4.2/ecj-4.4.2.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-catalina/8.0.28/tomcat-catalina-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-servlet-api/8.0.28/tomcat-servlet-api-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-jsp-api/8.0.28/tomcat-jsp-api-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-el-api/8.0.28/tomcat-el-api-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-juli/8.0.28/tomcat-juli-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-annotations-api/8.0.28/tomcat-annotations-api-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-api/8.0.28/tomcat-api-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-jni/8.0.28/tomcat-jni-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-coyote/8.0.28/tomcat-coyote-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-util-scan/8.0.28/tomcat-util-scan-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-util/8.0.28/tomcat-util-8.0.28.jar:/home/mateuszh/.m2/repository/javax/servlet/javax.servlet-api/4.0.1/javax.servlet-api-4.0.1.jar:/home/mateuszh/.local/share/JetBrains/Toolbox/apps/IDEA-C/ch-0/182.3684.101/lib/idea_rt.jar
java.io.FileNotFoundException: /home/mateuszh/jdk1.8.0_181/jre/lib/charsets.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/deploy.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/cldrdata.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/dnsns.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/jaccess.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/jfxrt.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/localedata.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/nashorn.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/sunec.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/sunjce_provider.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/sunpkcs11.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/zipfs.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/javaws.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/jce.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/jfr.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/jfxswt.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/jsse.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/management-agent.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/plugin.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/resources.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/rt.jar:/home/mateuszh/IdeaProjects/embedded/target/classes:/home/mateuszh/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.0.28/tomcat-embed-core-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/embed/tomcat-embed-jasper/8.0.28/tomcat-embed-jasper-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/embed/tomcat-embed-el/8.0.28/tomcat-embed-el-8.0.28.jar:/home/mateuszh/.m2/repository/org/eclipse/jdt/core/compiler/ecj/4.4.2/ecj-4.4.2.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-catalina/8.0.28/tomcat-catalina-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-servlet-api/8.0.28/tomcat-servlet-api-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-jsp-api/8.0.28/tomcat-jsp-api-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-el-api/8.0.28/tomcat-el-api-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-juli/8.0.28/tomcat-juli-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-annotations-api/8.0.28/tomcat-annotations-api-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-api/8.0.28/tomcat-api-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-jni/8.0.28/tomcat-jni-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-coyote/8.0.28/tomcat-coyote-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-util-scan/8.0.28/tomcat-util-scan-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-util/8.0.28/tomcat-util-8.0.28.jar:/home/mateuszh/.m2/repository/javax/servlet/javax.servlet-api/4.0.1/javax.servlet-api-4.0.1.jar:/home/mateuszh/.local/share/JetBrains/Toolbox/apps/IDEA-C/ch-0/182.3684.101/lib/idea_rt.jar (File name too long)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:225)
at java.util.zip.ZipFile.<init>(ZipFile.java:155)
at java.util.jar.JarFile.<init>(JarFile.java:166)
at java.util.jar.JarFile.<init>(JarFile.java:130)
at org.apache.catalina.startup.Tomcat.getWebappConfigFileFromJar(Tomcat.java:1137)
at org.apache.catalina.startup.Tomcat.getWebappConfigFile(Tomcat.java:1117)
at org.apache.catalina.startup.Tomcat.addWebapp(Tomcat.java:540)
at org.apache.catalina.startup.Tomcat.addWebapp(Tomcat.java:515)
at com.mateusz.tomcat.embedded.Launcher.startServer(Launcher.java:30)
at com.mateusz.tomcat.embedded.Launcher.main(Launcher.java:13)
Jul 30, 2018 6:18:09 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8888"]
Jul 30, 2018 6:18:09 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Jul 30, 2018 6:18:10 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Tomcat
Jul 30, 2018 6:18:10 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.28
Jul 30, 2018 6:18:10 PM org.apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[/embedded]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:916)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[/embedded]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
... 6 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.webresources.StandardRoot@51ff5a12]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4854)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4984)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
Caused by: java.lang.IllegalArgumentException: The main resource set specified [/home/mateuszh/jdk1.8.0_181/jre/lib/charsets.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/deploy.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/cldrdata.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/dnsns.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/jaccess.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/jfxrt.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/localedata.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/nashorn.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/sunec.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/sunjce_provider.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/sunpkcs11.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/ext/zipfs.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/javaws.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/jce.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/jfr.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/jfxswt.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/jsse.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/management-agent.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/plugin.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/resources.jar:/home/mateuszh/jdk1.8.0_181/jre/lib/rt.jar:/home/mateuszh/IdeaProjects/embedded/target/classes:/home/mateuszh/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.0.28/tomcat-embed-core-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/embed/tomcat-embed-jasper/8.0.28/tomcat-embed-jasper-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/embed/tomcat-embed-el/8.0.28/tomcat-embed-el-8.0.28.jar:/home/mateuszh/.m2/repository/org/eclipse/jdt/core/compiler/ecj/4.4.2/ecj-4.4.2.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-catalina/8.0.28/tomcat-catalina-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-servlet-api/8.0.28/tomcat-servlet-api-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-jsp-api/8.0.28/tomcat-jsp-api-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-el-api/8.0.28/tomcat-el-api-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-juli/8.0.28/tomcat-juli-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-annotations-api/8.0.28/tomcat-annotations-api-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-api/8.0.28/tomcat-api-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-jni/8.0.28/tomcat-jni-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-coyote/8.0.28/tomcat-coyote-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-util-scan/8.0.28/tomcat-util-scan-8.0.28.jar:/home/mateuszh/.m2/repository/org/apache/tomcat/tomcat-util/8.0.28/tomcat-util-8.0.28.jar:/home/mateuszh/.m2/repository/javax/servlet/javax.servlet-api/4.0.1/javax.servlet-api-4.0.1.jar:/home/mateuszh/.local/share/JetBrains/Toolbox/apps/IDEA-C/ch-0/182.3684.101/lib/idea_rt.jar] is not valid
at org.apache.catalina.webresources.StandardRoot.createMainResourceSet(StandardRoot.java:723)
at org.apache.catalina.webresources.StandardRoot.startInternal(StandardRoot.java:684)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 9 more
couldn't start the server
Jul 30, 2018 6:18:10 PM org.apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:916)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:439)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:769)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.startup.Tomcat.start(Tomcat.java:337)
at com.mateusz.tomcat.embedded.Launcher.startServer(Launcher.java:33)
at com.mateusz.tomcat.embedded.Launcher.main(Launcher.java:13)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:924)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<artifactId>embedded</artifactId>
<groupId>com.mateusz.tomcat</groupId>
<version>1.0.0</version>
<packaging>war</packaging>
<modelVersion>4.0.0</modelVersion>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<tomcat.version>8.0.28</tomcat.version>
</properties>
<build>
<plugins>
<!--create a jar to start the server-->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-launcher-jar</id>
<phase>prepare-package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- unpack jar into the war folder-->
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>prepare-package</phase>
<configuration>
<tasks>
<echo message="unzipping file"/>
<unzip src="${project.build.directory}/${project.build.finalName}-jar-with-dependencies.jar"
dest="${project.build.directory}/${project.build.finalName}/"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- make the war file-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<attachClasses>true</attachClasses>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>Launcher</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- Embedded tomcat -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-util</artifactId>
<version>${tomcat.version}</version>
</dependency>
<!-- JavaX -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
</dependencies>
和我的启动器
package com.mateusz.tomcat.embedded;
import org.apache.catalina.Context;
import org.apache.catalina.Host;
import org.apache.catalina.startup.Tomcat;
import java.io.File;
public class Launcher {
public static void main(String[] args) {
Launcher launcher = new Launcher();
try {
launcher.startServer();
} catch (Exception e) {
System.out.println("couldn't start the server");
}
}
private void startServer() throws Exception {
File war = new File(System.getProperty("java.class.path"));
Tomcat tomcat = new Tomcat();
tomcat.setPort(8888);
tomcat.setBaseDir(System.getProperty("user.dir"));
System.out.println("war: " + war);
Host host = tomcat.getHost();
host.setAppBase(System.getProperty("user.dir"));
host.setAutoDeploy(true);
host.setDeployOnStartup(true);
Context appContext = tomcat.addWebapp(host, "/embedded", war.getAbsolutePath());
System.out.println("Deployed " + appContext.getBaseName() + " as " + appContext.getDocBase());
tomcat.start();
tomcat.getServer().await();
}
}
答案 0 :(得分:0)
我已经通过改变一条车道解决了这个问题。
File war = new File(System.getProperty("java.class.path"));
更改为:
File war = new File(".");