exec-maven-plugin icon indicating copy to clipboard operation
exec-maven-plugin copied to clipboard

ClassNotFoundException when running exec-maven-plugin

Open amalik18 opened this issue 2 years ago • 2 comments

Hey so I have a AWS CDK package and I'm running mvn package and i get the following stack trace:

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.0.0:java (default-cli) on project java_cdk: An exception occured while executing the Java class. com.mikli.JavaCdkApp -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.0.0:java (default-cli) on project java_cdk: An exception occured while executing the Java class. com.mikli.JavaCdkApp
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    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:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occured while executing the Java class. com.mikli.JavaCdkApp
    at org.codehaus.mojo.exec.ExecJavaMojo.execute (ExecJavaMojo.java:311)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    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:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: java.lang.ClassNotFoundException: com.mikli.JavaCdkApp
    at java.net.URLClassLoader.findClass (URLClassLoader.java:445)
    at java.lang.ClassLoader.loadClass (ClassLoader.java:587)
    at java.lang.ClassLoader.loadClass (ClassLoader.java:520)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:246)
    at java.lang.Thread.run (Thread.java:833)
[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/MojoExecutionException
Subprocess exited with error 1

My CDK app adds a Lambda Function. The lambda function is stored as another maven package. The directory structure is as such:

CDKApp
-src
--main
---java
----com.mikli
-----JavaCdkApp
-----JavaCdkStack
--test
---java
----com.mikli
-----JavaCdkTest.java
-lambda
--hello_lambda (maven package)
---src
----main
-----java
------com.mikli
-------HelloLambdaHandler
----test
-----java

My pom.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
         xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.mikli</groupId>
    <artifactId>java_cdk</artifactId>
    <packaging>pom</packaging>
    <version>0.1</version>
    <modules>
        <module>lambda/hello_lambda</module>
    </modules>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <cdk.version>1.137.0</cdk.version>
        <junit.version>5.7.1</junit.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <includePluginDependencies>true</includePluginDependencies>
                    <mainClass>com.mikli.JavaCdkApp</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <!-- AWS Cloud Development Kit -->
        <dependency>
            <groupId>software.amazon.awscdk</groupId>
            <artifactId>core</artifactId>
            <version>${cdk.version}</version>
        </dependency>
        <dependency>
            <groupId>software.amazon.awscdk</groupId>
            <artifactId>sqs</artifactId>
            <version>${cdk.version}</version>
        </dependency>
        <dependency>
            <groupId>software.amazon.awscdk</groupId>
            <artifactId>lambda</artifactId>
            <version>${cdk.version}</version>
        </dependency>
        <dependency>
            <groupId>software.amazon.awscdk</groupId>
            <artifactId>assertions</artifactId>
            <version>${cdk.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
          <groupId>org.junit.jupiter</groupId>
          <artifactId>junit-jupiter</artifactId>
          <version>${junit.version}</version>
          <scope>test</scope>
        </dependency>
    </dependencies>
</project>

I can't seem to figure out why this is happening. Any help is greatly appreciated.

amalik18 avatar Dec 27 '21 06:12 amalik18

Hi

Just to mentioned that we had a simliar issue in our pipelines, i.e. not having specified the version until now and it started breaking with 3.1.0:

java.lang.NoClassDefFoundError: Could not initialize class com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl
     at com.sun.xml.bind.v2.model.impl.RuntimeTypeInfoSetImpl.<init> (RuntimeTypeInfoSetImpl.java:33)
     at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.createTypeInfoSet (RuntimeModelBuilder.java:98)
     at com.sun.xml.bind.v2.model.impl.ModelBuilder.<init> (ModelBuilder.java:132)
     at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.<init> (RuntimeModelBuilder.java:62)
     at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet (JAXBContextImpl.java:434)
     at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init> (JAXBContextImpl.java:282)
     at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init> (JAXBContextImpl.java:109)
     at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build (JAXBContextImpl.java:1142)
     at com.sun.xml.bind.v2.ContextFactory.createContext (ContextFactory.java:144)
     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
     at java.lang.reflect.Method.invoke (Method.java:566)
     at javax.xml.bind.ContextFinder.newInstance (ContextFinder.java:251)
     at javax.xml.bind.ContextFinder.newInstance (ContextFinder.java:240)
     at javax.xml.bind.ContextFinder.find (ContextFinder.java:363)
     at javax.xml.bind.JAXBContext.newInstance (JAXBContext.java:691)
     at org.apache.cxf.common.jaxb.JAXBContextCache$2.run (JAXBContextCache.java:345)
     at org.apache.cxf.common.jaxb.JAXBContextCache$2.run (JAXBContextCache.java:343)
     at java.security.AccessController.doPrivileged (Native Method)
     at org.apache.cxf.common.jaxb.JAXBContextCache.createContext (JAXBContextCache.java:343)
     at org.apache.cxf.common.jaxb.JAXBContextCache.getCachedContextAndSchemas (JAXBContextCache.java:245)
     at org.apache.cxf.jaxb.JAXBDataBinding.createJAXBContextAndSchemas (JAXBDataBinding.java:499)
     at org.apache.cxf.jaxb.JAXBDataBinding.initialize (JAXBDataBinding.java:358)
     at org.apache.cxf.service.factory.AbstractServiceFactoryBean.initializeDataBindings (AbstractServiceFactoryBean.java:87)
     at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass (ReflectionServiceFactoryBean.java:469)
     at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass (JaxWsServiceFactoryBean.java:693)
     at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.initializeServiceModel (ReflectionServiceFactoryBean.java:529)
     at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.create (ReflectionServiceFactoryBean.java:262)
     at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create (JaxWsServiceFactoryBean.java:199)
     at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint (AbstractWSDLBasedEndpointFactory.java:103)
     at org.apache.cxf.frontend.ClientFactoryBean.create (ClientFactoryBean.java:91)
     at org.apache.cxf.frontend.ClientProxyFactoryBean.create (ClientProxyFactoryBean.java:158)
     at org.apache.cxf.jaxws.JaxWsProxyFactoryBean.create (JaxWsProxyFactoryBean.java:142)
     ...

Happening on JDK 11.0.15 and Maven 3.8.6.

We are having the jaxb-runtime in the classpath, so not sure why it's not found.

andreasnef avatar Jul 28 '22 05:07 andreasnef

Can anyone of you share a minimal reproducer-project please? have you looked at the ITs in this repo to spot any differences?

bmarwell avatar Jul 29 '22 06:07 bmarwell