当前位置: 首页 > 知识库问答 >
问题:

noClassDefoundError:org/apache/catalina/lifecycleException

丁翊歌
2023-03-14

我正在做一个项目,希望将tomcat嵌入到Java的web应用程序中。我希望将这个应用程序转换成Java web start,这样就可以进行部署,任何下载该应用程序的人都可以在嵌入式服务器上使用该应用程序,而不必下载Tomcat。我面临的问题是,当我在eclipse上运行代码时,代码运行得很好,但当我将其转换为一个可下载文件时,它一开始就显示出我在标题中提到的错误。我以前有个错误说...java.lang.noClassDefoundError: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>

共有1个答案

邢和光
2023-03-14

嘿伙计们修复了这个错误。受到新错误的欢迎,但将它们修正为。这是一个相当简单的疑问为什么我以前没有考虑它。因此,我所做的只是添加jar href=“whichever jar was enside”。因此,根据我的理解,当我们在eclipse中jar文件时所做的打包并不是真的打包了所有必需的jar,或者它确实打包了,但它们在运行时并不有用,因为这时主类调用必需的jar而它们却丢失了。通过在href中添加这些必需的jar,它们将在运行时被调用,从而解决了您的问题。

我的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>
 类似资料:
  • huseyin@ubuntu:~$'/usr/local/oozie/oozie/oozie/oozie-setup.sh'sharelib create-fs hdfs:/hadoopcluster:10000 setting catalina_opts=“$catalina_opts-xmx1024m” 错误:发生了JNI错误,请检查线程“main”java.lang.noClassDeffo

  • 我试图调用我的Java方法,它是用Kettle Pentaho JAR编写的。当它抛出这样的错误时... 有什么解决办法吗?

  • 我刚刚在Linux RHEL6中安装了netbeans。我必须在conf/catalina/localhost/something.xml中为我的Java应用程序创建xml文件

  • 我有一个java应用程序,其中启动Equinox OSGi容器(版本3.10.1.V20140909-1633)并加载apache catalina springsource包和其他相关包。下面是我的config.ini文件。 当我连接到OSGi控制台并使用命令列出所有包时,我看到以下结果 在这里,包和是片段包,其父包是。 我们可以看到这3个捆绑包都是刚刚安装的。当我尝试用命令手动启动包时,我看到

  • 我刚把我的Mac OS更新到Catalina版本,我的Hybris服务器就停止打开了。因此,在命令./hybrisserver.sh start中,我得到以下内容 MacBook-Pro-Sasha:Platform sashayukhimchuk$./hybrisserver.sh开始在Tomcat上启动hybrisPlatform.../users/sashaukhimchuk/hybris/

  • 我开始转换所有64位,并注意Mac汇编语法。 我有东西要组装,但我立即遇到了一个奇怪的分段错误: QUIT通过宏defword定义如下: null 附注:是的,我可以让琼斯在Docker图像中完美地工作,但这是重点之外的。我真的希望它在卡特琳娜64位工作,开箱即用。