graalvm debug maven项目
时间: 2023-09-11 17:11:38 浏览: 220
maven 项目
要在Maven项目中使用GraalVM进行调试,需要使用GraalVM自带的调试器`jsadebugd`。下面是具体步骤:
1. 在POM文件中添加以下依赖项:
```xml
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
<version>${graalvm.version}</version>
<scope>provided</scope>
</dependency>
```
2. 在Maven命令行中运行以下命令:
```
mvn package -DskipTests -Pnative
```
3. 运行以下命令来启动调试器:
```
jsadebugd --port 8000 --jvmcpuset <cpu-set> --graalvm-home <graalvm-home>
```
其中,`<cpu-set>`是CPU集合的列表,`<graalvm-home>`是GraalVM的根目录。例如:
```
jsadebugd --port 8000 --jvmcpuset 0,1 --graalvm-home /usr/local/graalvm-ce-21.0.0
```
4. 在`pom.xml`文件中添加以下插件配置:
```xml
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>debug</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>native-image</executable>
<workingDirectory>${project.basedir}</workingDirectory>
<arguments>
<argument>--debug-attach=<hostname>:8000</argument>
<argument>--no-fallback</argument>
<argument>--allow-incomplete-classpath</argument>
<argument>--report-unsupported-elements-at-runtime</argument>
<argument>--initialize-at-build-time</argument>
<argument>--no-server</argument>
<argument>--verbose</argument>
<argument>--class-path</argument>
<classpath/>
<argument>--enable-all-security-services</argument>
<argument>--enable-url-protocols=http,https</argument>
<argument>--enable-https</argument>
<argument>--initialize-at-run-time=org.apache.maven.cli.MavenCli,org.codehaus.plexus.classworlds.launcher.Launcher</argument>
<argument>--initialize-at-run-time=org.codehaus.plexus.classworlds.realm.ClassRealm</argument>
<argument>--initialize-at-run-time=org.codehaus.plexus.configuration.PlexusConfigurationException</argument>
<argument>--initialize-at-run-time=org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration</argument>
<argument>--initialize-at-run-time=org.codehaus.plexus.configuration.xml.XmlPlexusConfigurationReader</argument>
<argument>--initialize-at-run-time=org.codehaus.plexus.util.xml.XmlStreamReaderException</argument>
<argument>--initialize-at-run-time=org.codehaus.plexus.util.xml.pull.XmlPullParserException</argument>
<argument>--initialize-at-run-time=org.codehaus.plexus.util.xml.pull.XmlPullParserFactory</argument>
<argument>--initialize-at-run-time=org.codehaus.plexus.util.xml.pull.XmlSerializer</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.RepositorySystem</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.RepositorySystemSession</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.artifact.Artifact</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.graph.Dependency</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.graph.DependencyNode</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.repository.ArtifactRepository</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.repository.LocalRepository</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.repository.RemoteRepository</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.resolution.ArtifactResolutionException</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.util.artifact.DefaultArtifact</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.util.graph.DefaultDependencyNode</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.util.graph.manager.DependencyManagerUtils</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.util.graph.manager.SessionDependencyManager</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.util.repository.DefaultAuthenticationSelector</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.util.repository.DefaultMirrorSelector</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.util.repository.DefaultProxySelector</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.util.repository.SimpleArtifactDescriptorPolicy</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.util.xml.DefaultXmlProcessor</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.util.xml.Xpp3DomBuilder</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.util.xml.Xpp3DomUtils</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.util.xml.pull.MXParser</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.util.xml.pull.XmlPullParser</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.util.xml.pull.XmlPullParserException</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.util.xml.pull.XmlPullParserFactory</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.util.xml.pull.XmlSerializer</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.version.Version</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.version.VersionConstraint</argument>
<argument>--initialize-at-run-time=org.sonatype.aether.version.VersionRange</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
```
5. 运行以下命令来启动调试:
```
mvn test
```
这将启动本地服务器,等待调试器连接。打开您的IDE调试器,并将其连接到本地服务器。这样,您就可以调试Maven项目了。
阅读全文