繁体   English   中英

错误:无法找到或加载主类 org.apache.catalina.startup.Bootstrap

[英]Error: Could not find or load main class org.apache.catalina.startup.Bootstrap

我正在使用 cargo-maven2-plugin 运行 tomcat 进行集成测试。 使用 7x 容器时效果很好。 我最近将它升级到 9x,它在 Ubuntu/Linux 机器上运行良好,但在 Mac(运行最新的操作系统版本)上不起作用。

当我查看容器日志时,它会列出以下日志:

Error: Could not find or load main class org.apache.catalina.startup.Bootstrap
Listening for transport dt_socket at address: 7998
Error: Could not find or load main class org.apache.catalina.startup.Bootstrap

当我查看货物日志时,它列出了以下日志:

The ' characters around the executable and arguments are
not part of the command.
[10:46:34.640][debug][talledLocalContainer]    +Task: java
[10:46:34.642][debug][talledLocalContainer] dropping /Users/myprojectpath/target/tomcat-9.0.22/bin/tomcat-juli.jar from path as it doesn't exist
[10:46:34.642][debug][talledLocalContainer] dropping /Users/myprojectpath/target/tomcat-9.0.22/bin/bootstrap.jar from path as it doesn't exist
[10:46:34.643][debug][talledLocalContainer] dropping /Users/myprojectpath/target/tomcat-9.0.22/bin/tomcat-juli.jar from path as it doesn't exist
[10:46:34.643][debug][talledLocalContainer] dropping /Users/myprojectpath/target/tomcat-9.0.22/bin/bootstrap.jar from path as it doesn't exist
[10:46:34.643][debug][talledLocalContainer] Executing '/Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home/jre/bin/java' with arguments:
'-Xdebug'
'-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=7998'
'-DprocessName=central'
'-Xms256m'
'-Xmx512m'
'-Dfile.encoding=utf-8'
'-Dhsqldb.database=/Users/myprojectpath/target/tomcat-9.0.22/tomcat/hsqldb/myprojectdbname'
'-Dhsqldb.dbname=myprojectdbname'
'-Dhsqldb.port=9001'
'-Duser.language=en'
'-Dcatalina.home=/Users/myprojectpath/target/tomcat-9.0.22'
'-Dcatalina.base=/Users/myprojectpath/target/tomcat-9.0.22/tomcat'
'-Djava.io.tmpdir=/Users/myprojectpath/target/tomcat-9.0.22/tomcat/temp'
'-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager'
'-Djava.util.logging.config.file=/Users/myprojectpath/target/tomcat-9.0.22/tomcat/conf/logging.properties'
'-classpath'
'/Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home/lib/tools.jar'
'org.apache.catalina.startup.Bootstrap'
'start'

这是插件的配置/设置:

<plugin>
  <groupId>org.codehaus.cargo</groupId>
  <artifactId>cargo-maven2-plugin</artifactId>
  <configuration>
      <configuration>
          <properties>
              <cargo.wait>false</cargo.wait>
              <cargo.jvmargs>${jvm.debug.options} -DprocessName=central -Xms256m -Xmx512m -Dfile.encoding=utf-8 -Dhsqldb.database=${catalina.home}/hsqldb/myprojectdbname -Dhsqldb.dbname=myprojectdbname -Dhsqldb.port=9001 -Duser.language=en</cargo.jvmargs>
          </properties>
      </configuration>
      <deployables>
      ....
      </deployables>
      </configuration>
  <executions>
      <execution>
          <id>start-container</id>
          <phase>package</phase>
          <goals>
              <goal>start</goal>
          </goals>
      </execution>
      <execution>
          <id>stop-container</id>
          <phase>post-integration-test</phase>
          <goals>
              <goal>stop</goal>
          </goals>
      </execution>
  </executions>
</plugin>

<profile>
    <id>tomcat9x</id>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <configuration>
                    <container>
                        <containerId>tomcat9x</containerId>
                        <artifactInstaller>
                            <groupId>com.mycomapany.tomcat</groupId>
                            <artifactId>tomcat</artifactId>
                            <version>${catalina.version}</version>
                            <type>zip</type>
                            <extractDir>${project.build.directory}</extractDir>
                        </artifactInstaller>
                        <output>${project.build.directory}/container.log</output>
                        <append>false</append>
                        <log>${project.build.directory}/cargo.log</log>
                        <timeout>600000</timeout>
                    </container>
                    <configuration>
                        <type>existing</type>
                        <home>${catalina.home}</home>
                        <properties>
                            <cargo.servlet.port>${catalina.port}</cargo.servlet.port>
                            <cargo.logging>high</cargo.logging>
                        </properties>
                    </configuration>
                </configuration>
            </plugin>
        </plugins>
    </build>
</profile>
</profiles>
<properties>
<catalina.port>12345</catalina.port>
<catalina.home>${project.build.directory}/tomcat-${catalina.version}/tomcat</catalina.home>
<jvm.debug.options>-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=7998</jvm.debug.options>
</properties>

我找到了解决问题的方法。

根据货物日志,类路径中的 tomcat-juli 和 bootstrap jar 都被删除。 那太好了。 为什么要添加一个不存在的罐子? 即这些 jar 不在以下位置: /Users/myprojectpath/target/tomcat-9.0.22/bin

但是他们住在哪里呢? 好吧,它们位于: /Users/myprojectpath/target/tomcat-9.0.22/tomcat/bin

进一步查看货物日志,java 任务是使用这些 jvm args 执行的,其中包括:

-Dcatalina.home=/Users/myprojectpath/target/tomcat-9.0.22
-Dcatalina.base=/Users/myprojectpath/target/tomcat-9.0.22/tomcat

现在连接点,tomcat-juli 和 bootstrap jar 被假定位于 catalina.home 但它们位于 catalina.base,不是吗? 容易修复,对吧?

那怎么设置catalina.home呢? 给cargo.jvm.args 添加一个额外的参数? Nää,没有用。 然后怎样呢? 因为它是一个 maven 货物插件/容器,所以可能有一个配置? 是的,在<container>下有一个叫做<home> <container> 最后!

不过,我不知道为什么 ubuntu/linux 机器不需要这个配置来运行本地 tomcat 容器进行集成测试。

但我确实理解 catalina.base 和 catalina.home 的目的:)

我清理了这个项目,它又开始工作了。

Project -> Clean 将删除任何现有的类文件并完全重建项目。 这里有关于 Eclipse 的clean功能的更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM