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

时间:2019-08-05 13:31:03

标签: java maven tomcat jvm maven-cargo

我正在使用cargo-maven2-plugin运行tomcat进行集成测试。使用7x容器时,效果很好。我最近将其升级到了9x,它在Ubuntu / Linux机器上可以正常工作,但在Mac(运行最新的OS版本)上不能正常工作。

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

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>

2 个答案:

答案 0 :(得分:0)

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

根据货物日志,来自类路径的tomcat-juli和引导罐都将被丢弃。太好了为什么要添加一个不存在的jar?也就是说,这些罐子不在以下位置:/Users/myprojectpath/target/tomcat-9.0.22/bin

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

进一步查看货运日志,使用以下jvm args执行了Java任务:

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

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

那么如何设置catalina.home?在cargo.jvm.args中添加一个额外的参数? Nää,没用。然后怎样呢?由于这是一个Maven货运插件/容器,可能会有配置吗?是的,在<home>下有一个叫做<container>的。最后!

我仍然不知道为什么ubuntu / linux机器不需要此配置即可运行本地tomcat容器进行集成测试。

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

答案 1 :(得分:0)

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

Project -> Clean 将删除任何现有的类文件并完全重建项目。此处提供了有关 Eclipse clean 函数的更多信息。