【问题标题】:Using VisualVM with Maven Cargo将 VisualVM 与 Maven Cargo 一起使用
【发布时间】:2021-02-25 18:29:18
【问题描述】:

我们使用 Maven Cargo 在本地启动我们的服务并在其上运行测试。下面是插件的配置:

            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <version>1.6.8</version>
                <configuration>
                    <container>
                        <containerId>tomcat8x</containerId>
                        <zipUrlInstaller>
                            <url>
                                https://www.someurl.com/tosome.zip
                            </url>
                        </zipUrlInstaller>
                        <dependencies>
                            <dependency>
                                <groupId>javax.mail</groupId>
                                <artifactId>mail</artifactId>
                                <!--<classpath>shared</classpath>-->
                            </dependency>
                        </dependencies>
                    </container>
                    <configuration>
                        <configfiles>
                            <configfile>
                                <file>${project.build.testOutputDirectory}/tomcat-conf/context.xml</file>
                                <todir>conf</todir>
                                <tofile>context.xml</tofile>
                            </configfile>
                        </configfiles>
                        <files>
                            <file>
                                <file>${project.build.testOutputDirectory}/extra-classpath</file>
                                <todir>shared/classes</todir>
                            </file>
                        </files>
                        <properties>
                            <cargo.start.jvmargs>
                                -Dcom.sun.management.jmxremote
                                -Dcom.sun.management.jmxremote.ssl=false
                                -Dcom.sun.management.jmxremote.authenticate=false
                                -Dcom.sun.management.jmxremote.port=1099
<!--                                 -Xdebug-->
<!--                                 -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000-->
<!--                                 -Xnoagent-->
<!--                                 -Djava.compiler=NONE-->
                            </cargo.start.jvmargs>
                            <cargo.servlet.port>${maven.tomcat.port}</cargo.servlet.port>
                            <cargo.tomcat.ajp.port>${cargo.tomcat.ajp.port}</cargo.tomcat.ajp.port>
                            <cargo.rmi.port>${cargo.rmi.port}</cargo.rmi.port>
                        </properties>
                    </configuration>
                    <deployables>
                        <deployable>
                            <groupId>our.stuff</groupId>
                            <artifactId>our-artifact</artifactId>
                            <type>war</type>
                        </deployable>
                    </deployables>
                </configuration>
                <executions>
                    <execution>
                        <id>start-server</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop-server</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

我们使用以下命令来启动 Cargo:

clean prepare-package cargo:run -Dcargo.tomcat.ajp.port=9080 -Dmaven.tomcat.port=8080 -Dcargo.rmi.port=9070

我尝试使用普通的 IntelliJ 运行按钮和 VisualVM 启动器启动该进程:

在这两种情况下,本地 Tomcat 服务器正常启动并像往常一样等待 8080 上的请求。但是,该进程并未出现在 VisualVM 应用程序的Local 列表中。

我尝试在 &lt;cargo.start.jvmargs&gt; 中使用和不使用多个 -Dcom.sun.management.jmxremote 参数。

我还尝试通过右键单击 Local 项目并选择 Add JMX Connection 并输入给货物 (1099) 的端口值来在本地添加连接:

但是什么也没发生。

精度:我对 VisualVM 很陌生,对所有这些东西都不是 100% 确定的。尤其是选择“JMX”。

【问题讨论】:

    标签: java jmx visualvm maven-cargo


    【解决方案1】:

    当您运行启动CargoMaven 命令时,您最终会得到两个新进程。在上图中,它是Apache Maven (pid 22512)Tomcat (pid 14080)(注意:PID 无关紧要,很可能在您的机器上有所不同)。

    由于我们的 Cargo 被配置为使用 Tomcat,因此 Tomcat 进程就是我们想要分析的进程。

    我之前注意到并尝试过,但是VisualVM 应用程序非常无响应,因此我开始探索其他可能性。此外,我第二次尝试这样做并让Profiler 完全初始化自己,这东西在几分钟内完全没有响应。

    【讨论】:

      猜你喜欢
      • 2013-02-01
      • 2013-08-09
      • 1970-01-01
      • 2011-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-22
      • 2013-08-19
      相关资源
      最近更新 更多