gpt4 book ai didi

java.lang.NoClassDefFoundError : org/apache/catalina/LifecycleException

转载 作者:行者123 更新时间:2023-11-30 06:05:32 33 4
gpt4 key购买 nike

我正在开发一个项目,该项目希望将 tomcat 嵌入到 java web 应用程序中。我希望将此应用程序转换为java web start,以便可以部署它,并且下载该应用程序的任何人都可以在嵌入式服务器上使用该应用程序,而无需下载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 文件时完成的打包的理解,它并没有真正打包所有必要的 jar,或者可能打包了,但它们在运行时没有用,因为那是主类调用必要的 jar 的时候他们失踪了。通过在 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>

关于java.lang.NoClassDefFoundError : org/apache/catalina/LifecycleException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51416558/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com