java.lang.NoClassDefFoundError: org/apache/catalina/LifecycleException
java.lang.NoClassDefFoundError: org/apache/catalina/LifecycleException
我正在开发一个项目,希望将 tomcat 嵌入到 java 网络应用程序中。
我希望将此应用程序转换为 java web 启动,以便它可以部署并且任何下载该应用程序的人都可以在嵌入式服务器上使用该应用程序而无需下载 tomcat。
我面临的问题是,当我在 eclipse 上 运行 时,代码 运行 是完美的,但是当我将它转换为可下载文件时,该文件在开始时显示我在标题中提到的错误。
我之前有一个错误说... java.lang.NoClassDefFoundError: org/apache/catalina/Context
我通过使用 Catalina jar 文件作为 jnlp 文件中的资源 href 之一来修复此问题。
据我所知,此 LifecycleException 是 Catalina.jar 的一部分。
请帮助解决我的错误,或者至少为我指出正确的方向来解决它。
我正在 运行 使用 Eclipse IDE 上的 Maven 项目编写代码。
谢谢!
package com.N.VJ;
import java.io.File;
import javax.servlet.ServletException;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.Tomcat;
public class App {
public static void main(String[] args) throws LifecycleException,
InterruptedException, ServletException {
String docBase = "src/main/webapp/";
Tomcat tomcat = new Tomcat();
String webPort = System.getenv("PORT");
if(webPort == null || webPort.isEmpty()) {
webPort = "8088";
}
tomcat.setPort(Integer.valueOf(webPort));
tomcat.addWebapp("/", new File(docBase).getAbsolutePath());
System.out.println("configuring app with basedir: " + new File("./" +
docBase).getAbsolutePath());
tomcat.start();
tomcat.getServer().await();
}
}
pom.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tom1</groupId>
<artifactId>cat1</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>cat1 Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<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.embed</groupId>
<artifactId>tomcat-embed-logging-juli</artifactId>
<version>${tomcat.version}</version>
</dependency>
</dependencies>
<build>
<finalName>cat1</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.tom1.cat1.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<port>${tomcat.port}</port>
<path>/</path>
</configuration>
<executions>
<execution>
<id>tomcat-run</id>
<goals>
<goal>exec-war-only</goal>
</goals>
<phase>package</phase>
<configuration>
<path>/</path>
<port>${tomcat.port}</port>
<attachArtifactClassifierType>war</attachArtifactClassifierType>
<mainClass>org.apache.tomcat.maven.runner.Tomcat8RunnerCli</mainClass>
<extraDependencies>
<extraDependency>
<groupId>com.nitorcreations</groupId>
<artifactId>tomcat8-war-runner</artifactId>
<version>1.0</version>
</extraDependency>
</extraDependencies>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-util</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-coyote</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-api</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-dbcp</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jsp-api</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper-el</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-el-api</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-tribes</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina-ha</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-annotations-api</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-juli</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-juli</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-log4j</artifactId>
<version>${tomcat.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>tomcat-run</id>
<goals>
<goal>exec-war-only</goal>
</goals>
<phase>package</phase>
<configuration>
<warRunDependencies>
<warRunDependency>
<dependency>
<groupId>com.tom1</groupId>
<artifactId>cat1</artifactId>
<version>4</version>
<type>war</type>
</dependency>
<dependency>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.3-SNAPSHOT</version>
<type>maven-plugin</type>
</dependency>
<contextPath>/</contextPath>
</warRunDependency>
</warRunDependencies>
<enableNaming>true</enableNaming>
<extraDependencies>
<extraDependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.1.3.1</version>
</extraDependency>
<extraDependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</extraDependency>
</extraDependencies>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<tomcat.version>8.0.48</tomcat.version>
</properties>
</project>
JNLP 文件
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+"
codebase="http://localhost:8080/TCApp"
href="http://localhost:8080/TCApp/SO.jnlp">
<information>
<title>Hello World</title>
<vendor>Noel Joseph</vendor>
<homepage href="http://localhost:8080/TCApp/display.html" />
<description> Hello World</description>
</information>
<security>
<all-permissions />
</security>
<resources>
<j2se version="1.4+" href="http://java.sun.com/products/autodl/j2se"/>
<jar href="SO.jar" />
<jar href="catalina-6.0.29.jar" />
<jar href="catalina-ha-6.0.29.jar" />
</resources>
<application-desc main-class="com.N.VJ.App"/>
</jnlp>
大家好,修正了错误。
受到新错误的欢迎,但已将其修复。
很简单,想知道为什么我以前没有考虑过它。
所以我所做的就是添加 jar href =“需要哪个 jar”。
因此,根据我的理解,当我们在 eclipse 中打包文件时,它并没有真正打包所有必要的 jar,或者它可能打包了,但它们在 运行 时间内没有用,因为那是主要 class 需要必要的罐子,但它们不见了。
通过在 href 中添加这些必要的 jar,它们会在 运行 时间和 TADA 期间被调用,你的问题就解决了。
我的 JNLP 文件最后看起来像这样。
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+"
codebase="http://localhost:8080/TCApp"
href="http://localhost:8080/TCApp/SO.jnlp">
<information>
<title>Hello World</title>
<vendor>Noel Joseph</vendor>
<homepage href="http://localhost:8080/TCApp/display.html" />
<description> Hello World</description>
</information>
<security>
<all-permissions />
</security>
<resources>
<j2se version="1.4+" href="http://java.sun.com/products/autodl/j2se"/>
<jar href="New3.jar" main="true"/>
<jar href="tomcat-catalina-9.0.10.jar" />
<jar href="javax.servlet.jar" />
<jar href="javax.servlet-api-3.0.1.jar" />
<jar href="tomcat-util-9.0.10.jar" />
<jar href="tomcat-util-scan-9.0.10.jar" />
<jar href="tomcat-juli-9.0.10.jar" />
<jar href="tomcat-coyote-9.0.10.jar" />
<jar href="tomcat-api-9.0.10.jar" />
<jar href="tomcat-jni-9.0.10.jar" />
<jar href="tomcat-jsp-api-9.0.10.jar" />
<jar href="commons-logging-1.2.jar" />
<property name="sun.java2d.noddraw"
value="true"/>
</resources>
<application-desc main-class="com.NO.JO.App"/>
</jnlp>
我正在开发一个项目,希望将 tomcat 嵌入到 java 网络应用程序中。 我希望将此应用程序转换为 java web 启动,以便它可以部署并且任何下载该应用程序的人都可以在嵌入式服务器上使用该应用程序而无需下载 tomcat。 我面临的问题是,当我在 eclipse 上 运行 时,代码 运行 是完美的,但是当我将它转换为可下载文件时,该文件在开始时显示我在标题中提到的错误。 我之前有一个错误说... java.lang.NoClassDefFoundError: org/apache/catalina/Context 我通过使用 Catalina jar 文件作为 jnlp 文件中的资源 href 之一来修复此问题。 据我所知,此 LifecycleException 是 Catalina.jar 的一部分。 请帮助解决我的错误,或者至少为我指出正确的方向来解决它。 我正在 运行 使用 Eclipse IDE 上的 Maven 项目编写代码。 谢谢!
package com.N.VJ;
import java.io.File;
import javax.servlet.ServletException;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.Tomcat;
public class App {
public static void main(String[] args) throws LifecycleException,
InterruptedException, ServletException {
String docBase = "src/main/webapp/";
Tomcat tomcat = new Tomcat();
String webPort = System.getenv("PORT");
if(webPort == null || webPort.isEmpty()) {
webPort = "8088";
}
tomcat.setPort(Integer.valueOf(webPort));
tomcat.addWebapp("/", new File(docBase).getAbsolutePath());
System.out.println("configuring app with basedir: " + new File("./" +
docBase).getAbsolutePath());
tomcat.start();
tomcat.getServer().await();
}
}
pom.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tom1</groupId>
<artifactId>cat1</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>cat1 Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<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.embed</groupId>
<artifactId>tomcat-embed-logging-juli</artifactId>
<version>${tomcat.version}</version>
</dependency>
</dependencies>
<build>
<finalName>cat1</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.tom1.cat1.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<port>${tomcat.port}</port>
<path>/</path>
</configuration>
<executions>
<execution>
<id>tomcat-run</id>
<goals>
<goal>exec-war-only</goal>
</goals>
<phase>package</phase>
<configuration>
<path>/</path>
<port>${tomcat.port}</port>
<attachArtifactClassifierType>war</attachArtifactClassifierType>
<mainClass>org.apache.tomcat.maven.runner.Tomcat8RunnerCli</mainClass>
<extraDependencies>
<extraDependency>
<groupId>com.nitorcreations</groupId>
<artifactId>tomcat8-war-runner</artifactId>
<version>1.0</version>
</extraDependency>
</extraDependencies>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-util</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-coyote</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-api</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-dbcp</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jsp-api</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper-el</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-el-api</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-tribes</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina-ha</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-annotations-api</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-juli</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-juli</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-log4j</artifactId>
<version>${tomcat.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>tomcat-run</id>
<goals>
<goal>exec-war-only</goal>
</goals>
<phase>package</phase>
<configuration>
<warRunDependencies>
<warRunDependency>
<dependency>
<groupId>com.tom1</groupId>
<artifactId>cat1</artifactId>
<version>4</version>
<type>war</type>
</dependency>
<dependency>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.3-SNAPSHOT</version>
<type>maven-plugin</type>
</dependency>
<contextPath>/</contextPath>
</warRunDependency>
</warRunDependencies>
<enableNaming>true</enableNaming>
<extraDependencies>
<extraDependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.1.3.1</version>
</extraDependency>
<extraDependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</extraDependency>
</extraDependencies>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<tomcat.version>8.0.48</tomcat.version>
</properties>
</project>
JNLP 文件
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+"
codebase="http://localhost:8080/TCApp"
href="http://localhost:8080/TCApp/SO.jnlp">
<information>
<title>Hello World</title>
<vendor>Noel Joseph</vendor>
<homepage href="http://localhost:8080/TCApp/display.html" />
<description> Hello World</description>
</information>
<security>
<all-permissions />
</security>
<resources>
<j2se version="1.4+" href="http://java.sun.com/products/autodl/j2se"/>
<jar href="SO.jar" />
<jar href="catalina-6.0.29.jar" />
<jar href="catalina-ha-6.0.29.jar" />
</resources>
<application-desc main-class="com.N.VJ.App"/>
</jnlp>
大家好,修正了错误。 受到新错误的欢迎,但已将其修复。 很简单,想知道为什么我以前没有考虑过它。 所以我所做的就是添加 jar href =“需要哪个 jar”。 因此,根据我的理解,当我们在 eclipse 中打包文件时,它并没有真正打包所有必要的 jar,或者它可能打包了,但它们在 运行 时间内没有用,因为那是主要 class 需要必要的罐子,但它们不见了。 通过在 href 中添加这些必要的 jar,它们会在 运行 时间和 TADA 期间被调用,你的问题就解决了。
我的 JNLP 文件最后看起来像这样。
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+"
codebase="http://localhost:8080/TCApp"
href="http://localhost:8080/TCApp/SO.jnlp">
<information>
<title>Hello World</title>
<vendor>Noel Joseph</vendor>
<homepage href="http://localhost:8080/TCApp/display.html" />
<description> Hello World</description>
</information>
<security>
<all-permissions />
</security>
<resources>
<j2se version="1.4+" href="http://java.sun.com/products/autodl/j2se"/>
<jar href="New3.jar" main="true"/>
<jar href="tomcat-catalina-9.0.10.jar" />
<jar href="javax.servlet.jar" />
<jar href="javax.servlet-api-3.0.1.jar" />
<jar href="tomcat-util-9.0.10.jar" />
<jar href="tomcat-util-scan-9.0.10.jar" />
<jar href="tomcat-juli-9.0.10.jar" />
<jar href="tomcat-coyote-9.0.10.jar" />
<jar href="tomcat-api-9.0.10.jar" />
<jar href="tomcat-jni-9.0.10.jar" />
<jar href="tomcat-jsp-api-9.0.10.jar" />
<jar href="commons-logging-1.2.jar" />
<property name="sun.java2d.noddraw"
value="true"/>
</resources>
<application-desc main-class="com.NO.JO.App"/>
</jnlp>