Error: Could not find or load main class 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(运行 最新的 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'
这是插件的 configuration/setup:
<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 都被丢弃了。那太好了。为什么要添加一个不存在的罐子?即这些罐子不在位置:/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 罐子假设位于 catalina.home 但它们位于 catalina.base,不是吗?很容易修复,对吧?
那么catalina.home怎么设置呢?向 cargo.jvm.args 添加一个额外的参数? Nää,没用。然后怎样呢?因为它是一个 maven cargo plugin/container 可能有一个配置?是的,<container>
下有一个叫做 <home>
。最后!
仍然,我不知道为什么 ubuntu/linux 机器不需要此配置来 运行 本地 tomcat 容器进行集成测试。
但我确实理解 catalina.base 和 catalina.home 的目的 :)
我清理了项目,它又开始工作了。
Project -> Clean 将删除任何现有的 class 文件并完全重建项目。这里有关于 Eclipse 的 clean 函数的更多信息。
我正在使用 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'
这是插件的 configuration/setup:
<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 都被丢弃了。那太好了。为什么要添加一个不存在的罐子?即这些罐子不在位置:/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 罐子假设位于 catalina.home 但它们位于 catalina.base,不是吗?很容易修复,对吧?
那么catalina.home怎么设置呢?向 cargo.jvm.args 添加一个额外的参数? Nää,没用。然后怎样呢?因为它是一个 maven cargo plugin/container 可能有一个配置?是的,<container>
下有一个叫做 <home>
。最后!
仍然,我不知道为什么 ubuntu/linux 机器不需要此配置来 运行 本地 tomcat 容器进行集成测试。
但我确实理解 catalina.base 和 catalina.home 的目的 :)
我清理了项目,它又开始工作了。
Project -> Clean 将删除任何现有的 class 文件并完全重建项目。这里有关于 Eclipse 的 clean 函数的更多信息。