When running mvn test -e -X
why is build failing with java.lang.ClassNotFoundException: java.net.http.HttpResponse?
I am using java 17 My stack trace is:
Running job testJava17ClientSamples ...
openjdk version "17.0.9" 2023-10-17
OpenJDK Runtime Environment Temurin-17.0.9+9 (build 17.0.9+9)
OpenJDK 64-Bit Server VM Temurin-17.0.9+9 (build 17.0.9+9, mixed mode, sharing)
[1mApache Maven 3.9.5 (57804ffe001d7215b5e7bcb531cf83df38f93546)[m
Maven home: /opt/apache-maven
Java version: 17.0.9, vendor: Eclipse Adoptium, runtime: /usr/local/jdk-17.0.9
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.15.0-1053-aws", arch: "amd64", family: "unix"
[0m[0mApache Maven 3.9.5 (57804ffe001d7215b5e7bcb531cf83df38f93546)
Maven home: /opt/apache-maven
Java version: 17.0.9, vendor: Eclipse Adoptium, runtime: /usr/local/jdk-17.0.9
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.15.0-1053-aws", arch: "amd64", family: "unix"
[DEBUG] Created new class realm maven.api
[DEBUG] Importing foreign packages into class realm maven.api
[DEBUG] Imported: javax.annotation.* < plexus.core
...
[DEBUG] =======================================================================
[INFO]
[INFO] ----------------< org.openapijsonschematools:petstore >-----------------
[INFO] Building petstore 0.0.1
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
...
(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:568)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
Caused by: java.lang.NoClassDefFoundError: java/net/http/HttpResponse
at java.lang.Class.getDeclaredMethods0 (Native Method)
at java.lang.Class.privateGetDeclaredMethods (Class.java:3402)
at java.lang.Class.getMethodsRecursive (Class.java:3543)
at java.lang.Class.getMethod0 (Class.java:3529)
at java.lang.Class.getMethod (Class.java:2225)
at org.apache.maven.surefire.util.ReflectionUtils.tryGetMethod (ReflectionUtils.java:57)
at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.isSuiteOnly (JUnit3TestChecker.java:64)
at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.isValidJUnit3Test (JUnit3TestChecker.java:59)
at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.accept (JUnit3TestChecker.java:54)
at org.apache.maven.surefire.common.junit4.JUnit4TestChecker.accept (JUnit4TestChecker.java:51)
at org.apache.maven.surefire.util.DefaultDirectoryScanner.locateTestClasses (DefaultDirectoryScanner.java:84)
at org.apache.maven.surefire.junitcore.JUnitCoreProvider.scanClassPath (JUnitCoreProvider.java:190)
at org.apache.maven.surefire.junitcore.JUnitCoreProvider.getSuitesAsList (JUnitCoreProvider.java:147)
at org.apache.maven.surefire.junitcore.JUnitCoreProvider.getSuites (JUnitCoreProvider.java:102)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:568)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray (ReflectionUtils.java:189)
at org.apache.maven.surefire.util.ReflectionUtils.invokeGetter (ReflectionUtils.java:69)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.getSuites (ProviderFactory.java:148)
at org.apache.maven.plugin.surefire.booterclient.ForkStarter.getSuitesIterator (ForkStarter.java:317)
at org.apache.maven.plugin.surefire.booterclient.ForkStarter.runSuitesForkPerTestSet (ForkStarter.java:149)
at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run (ForkStarter.java:118)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider (AbstractSurefireMojo.java:199)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAllProviders (AbstractSurefireMojo.java:176)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked (AbstractSurefireMojo.java:135)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute (AbstractSurefireMojo.java:98)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:568)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
Caused by: java.lang.ClassNotFoundException: java.net.http.HttpResponse
at java.net.URLClassLoader.findClass (URLClassLoader.java:445)
at java.lang.ClassLoader.loadClass (ClassLoader.java:592)
at java.lang.ClassLoader.loadClass (ClassLoader.java:525)
at org.apache.maven.surefire.booter.IsolatedClassLoader.loadClass (IsolatedClassLoader.java:97)
at java.lang.Class.getDeclaredMethods0 (Native Method)
at java.lang.Class.privateGetDeclaredMethods (Class.java:3402)
at java.lang.Class.getMethodsRecursive (Class.java:3543)
at java.lang.Class.getMethod0 (Class.java:3529)
at java.lang.Class.getMethod (Class.java:2225)
at org.apache.maven.surefire.util.ReflectionUtils.tryGetMethod (ReflectionUtils.java:57)
at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.isSuiteOnly (JUnit3TestChecker.java:64)
at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.isValidJUnit3Test (JUnit3TestChecker.java:59)
at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.accept (JUnit3TestChecker.java:54)
at org.apache.maven.surefire.common.junit4.JUnit4TestChecker.accept (JUnit4TestChecker.java:51)
at org.apache.maven.surefire.util.DefaultDirectoryScanner.locateTestClasses (DefaultDirectoryScanner.java:84)
at org.apache.maven.surefire.junitcore.JUnitCoreProvider.scanClassPath (JUnitCoreProvider.java:190)
at org.apache.maven.surefire.junitcore.JUnitCoreProvider.getSuitesAsList (JUnitCoreProvider.java:147)
at org.apache.maven.surefire.junitcore.JUnitCoreProvider.getSuites (JUnitCoreProvider.java:102)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:568)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray (ReflectionUtils.java:189)
at org.apache.maven.surefire.util.ReflectionUtils.invokeGetter (ReflectionUtils.java:69)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.getSuites (ProviderFactory.java:148)
at org.apache.maven.plugin.surefire.booterclient.ForkStarter.getSuitesIterator (ForkStarter.java:317)
at org.apache.maven.plugin.surefire.booterclient.ForkStarter.runSuitesForkPerTestSet (ForkStarter.java:149)
at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run (ForkStarter.java:118)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider (AbstractSurefireMojo.java:199)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAllProviders (AbstractSurefireMojo.java:176)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked (AbstractSurefireMojo.java:135)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute (AbstractSurefireMojo.java:98)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:568)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
[DEBUG] Shutting down adapter factory; available factories [file-lock, rwlock-local, semaphore-local, noop]; available name mappers [discriminating, file-gav, file-hgav, file-static, gav, static]
[DEBUG] Shutting down 'file-lock' factory
[DEBUG] Shutting down 'rwlock-local' factory
[DEBUG] Shutting down 'semaphore-local' factory
[DEBUG] Shutting down 'noop' factory
My pom.xml is:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.openapijsonschematools</groupId>
<artifactId>petstore</artifactId>
<packaging>jar</packaging>
<name>petstore</name>
<version>1.0.0</version>
<url>https://github.com/openapi-json-schema-tools/openapi-json-schema-generator</url>
<description>OpenAPI Java</description>
<scm>
<connection>scm:git:git@github.com:openapi-json-schema-tools/openapi-json-schema-generator.git</connection>
<developerConnection>scm:git:git@github.com:openapi-json-schema-tools/openapi-json-schema-generator.git</developerConnection>
<url>https://github.com/openapi-json-schema-tools/openapi-json-schema-generator</url>
</scm>
<licenses>
<license>
<name>Unlicense</name>
<url>https://www.apache.org/licenses/LICENSE-2.0.html</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<name>OpenAPI-Generator Contributors</name>
<email>team@openapijsonschematools.org</email>
<organization>OpenAPITools.org</organization>
<organizationUrl>http://openapijsonschematools.org</organizationUrl>
</developer>
</developers>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<fork>true</fork>
<meminitial>128m</meminitial>
<maxmem>512m</maxmem>
<compilerArgument>-Xlint:all</compilerArgument>
<compilerArgs combine.children="append">
<arg>-Awarns</arg>
<arg>-J-Xss4m</arg><!-- Compiling the generated JSON.java file may require larger stack size. -->
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>org.checkerframework</groupId>
<artifactId>checker</artifactId>
<version>${checker-version}</version>
</path>
</annotationProcessorPaths>
<annotationProcessors>
<annotationProcessor>
org.checkerframework.checker.nullness.NullnessChecker
</annotationProcessor>
</annotationProcessors>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>2.2.0</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<systemProperties>
<property>
<name>loggerPath</name>
<value>conf/log4j.properties</value>
</property>
</systemProperties>
<argLine>-Xms512m -Xmx1500m</argLine>
<parallel>methods</parallel>
<forkMode>pertest</forkMode>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- attach test jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
<configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.10</version>
<executions>
<execution>
<id>add_sources</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add_test_sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.2</version>
<configuration>
<doclint>none</doclint>
<source>1.8</source>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!-- @Nullable annotations -->
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
<version>${checker-version}</version>
</dependency>
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker</artifactId>
<version>${checker-version}</version>
</dependency>
<!-- json -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<checker-version>3.42.0</checker-version>
<maven-plugin-version>1.0.0</maven-plugin-version>
<junit-version>4.13.2</junit-version>
</properties>
</project>
java.net.http is literally built into the standard library. Why is it not being found? How do I fix this?
Build and testing works on my local machine when run from intelij using build project and run configuration
My PR with this issue is here: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator/pull/391 CircleCI run with trace: https://app.circleci.com/pipelines/github/openapi-json-schema-tools/openapi-json-schema-generator/3712/workflows/733c1f49-de14-4887-a5ba-a9d5b3318601/jobs/17623
Failing step:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project petstore: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test failed: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null: java/net/http/HttpResponse: java.net.http.HttpResponse -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project petstore: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test failed: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null
This was caused by the maven-surefile plugin being out of date. When When the below updates are made to pom.xml, mvn test
passes:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<systemProperties>
<property>
<name>loggerPath</name>
<value>conf/log4j.properties</value>
</property>
</systemProperties>
<argLine>-Xms512m -Xmx1500m</argLine>
<parallel>classes</parallel>
<useUnlimitedThreads>true</useUnlimitedThreads>
</configuration>
</plugin>