java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor

482 views
Skip to first unread message

Truong Nguyen Xuan

unread,
Jul 13, 2023, 6:38:30 AM7/13/23
to Codehaus Cargo
Hi,

I tried use cargo to deploy war to an embedded Jetty server, but got the exception java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor.

My environment is:
  • Cargo plugin: 1.10.6
  • Java 17
When I run the command cargo:run, I got the exception as below:
2023-07-13 10:32:56.607:WARN :oejw.WebAppContext:Thread-2: Failed startup of context o.e.j.w.webappcontext@2c47a053{/test,file:///tmp/jetty-0_0_0_0-8181-test-snapshot_war-_any-12504020395893202514/webapp/,unavailable}{/home/centos/.m2/repository/com/test/test-snapshot.war}
java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor
at org.eclipse.jetty.annotations.AnnotationConfiguration.createAnnotationParser(AnnotationConfiguration.java:586)

And here is my configuration:
<build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven3-plugin</artifactId>
                <version>1.10.6</version>
                <executions>
                    <execution>
                        <id>start-container</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                        <configuration>
                            <wait>false</wait>
                        </configuration>
                    </execution>
                    <execution>
                        <id>stop-container</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <configuration>
                        <properties>
                            <cargo.servlet.port>${cargo.servlet.port}</cargo.servlet.port>
                            <cargo.logging>medium</cargo.logging>
                        </properties>
                    </configuration>
                    <container>
                        <timeout>2980000</timeout>
                        <containerId>jetty10x</containerId>
                        <type>embedded</type>
                        <dependencies>
                            <dependency>
                                <location>${basedir}/target/test-classes/</location>
                            </dependency>
                            <dependency>
                                <location>${basedir}/src/robot/shared/classes</location>
                            </dependency>
                        </dependencies>
                        <systemProperties>
                            <greenmail.auth.disabled>true</greenmail.auth.disabled>
                        </systemProperties>
                    </container>
                </configuration>
            </plugin>
        </plugins>
    </build>

I have tried to add a dependency from asm but have no success.

Can anyone give me a hand on this?

S. Ali Tokmen

unread,
Jul 13, 2023, 7:37:10 AM7/13/23
to codehau...@googlegroups.com
Hi Truong

Confusingly, NoClassDefFoundError tends to happen when the same class is in the classpath multiple times, with different versions.

One way to fix wild be to hunt for the double definition and remove / exclude it.

A much easier way is to use the installed Jetty container, which will execute in its JVM (and hence clean classpath). You can use an ArtifactInstaller (see https://codehaus-cargo.github.io/cargo/Installer.html towards the end of the page) for Maven to deal with downloading the Jetty artifacts. Besides giving you a clean and realistic environnent, the installed container also has the advantage that you can choose the exact Jetty version you'd like to use. 

--
You received this message because you are subscribed to the Google Groups "Codehaus Cargo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codehaus-carg...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/codehaus-cargo/f0963417-30b5-4ac8-9489-70be31254965n%40googlegroups.com.

Truong Nguyen Xuan

unread,
Jul 13, 2023, 11:59:51 AM7/13/23
to Codehaus Cargo
Hi Ali,

Thanks for your reply, I have added the ArtifactInstaller but the error still occurs.

Could you please help to check if I put and use it in the right place, here is what I change:
                    <container>
                        <timeout>2980000</timeout>
                        <containerId>jetty10x</containerId>
                        <type>embedded</type>
                        <artifactInstaller>
                            <groupId>org.eclipse.jetty</groupId>
                            <artifactId>jetty-distribution</artifactId>
                            <version>10.0.0.beta1</version>
                        </artifactInstaller>

                        <dependencies>
                            <dependency>
                                <location>${basedir}/target/test-classes/</location>
                            </dependency>
                            <dependency>
                                <location>${basedir}/src/robot/shared/classes</location>
                            </dependency>
                        </dependencies>
                        <systemProperties>
                            <greenmail.auth.disabled>true</greenmail.auth.disabled>
                        </systemProperties>
                    </container>

I also tested with this artifactInstaller but have no success:
<artifactInstaller>
    <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-home</artifactId>
      <version>10.0.15</version>
</artifactInstaller>

S. Ali Tokmen

unread,
Jul 13, 2023, 1:16:11 PM7/13/23
to codehau...@googlegroups.com
Hi Truong

Please remove the embedded type - The default is anyways the installed container.

Truong Nguyen Xuan

unread,
Jul 13, 2023, 11:41:48 PM7/13/23
to Codehaus Cargo
Hi Ali,

I have removed the embedded and now I got this error:
[ERROR] Starting container [org.codehaus.cargo.container.jetty.Jetty10xInstalledLocalContainer@446c8c72] failed
org.codehaus.cargo.container.ContainerException: Failed to create a Jetty 10.0.0.beta1 standalone configuration: Source file [/home/centos/work/trunk/uat_services/target/test-classes] is not a file
    at org.codehaus.cargo.container.spi.configuration.AbstractLocalConfiguration.configure (AbstractLocalConfiguration.java:276)

There are some script and properties files that used to be shared for modules that I need to test.
It worked fine for the embedded type.

Is there another way to define it?

Codehaus Cargo

unread,
Jul 14, 2023, 2:01:27 AM7/14/23
to Codehaus Cargo
Hi Truong

I see - Your use case is best satisfied with what we described in https://codehaus-cargo.github.io/cargo/Application+Classpath.html

S. Ali Tokmen

unread,
Jul 14, 2023, 6:15:12 AM7/14/23
to codehau...@googlegroups.com
Hi Nguyen

Indeed, when you use the methodology in https://codehaus-cargo.github.io/cargo/Application+Classpath.html (which in your case would imply adding a <classpath>shared</classpath> element in each dependency folder) you can keep on using folders. 

As for the Java version, this is indeed weird. Can you enforce the JDK the container is using? Its described in cargo.java.home property of the container. 

Regards

On 14 Jul 2023 10:33, Nguyen Xuan Truong <nxtru...@gmail.com> wrote:
That's weird, I'm using java 17, and also set JAVA_HOME to openjdk17, as below:
[centos@localhost uat_services]$ java -version
openjdk version "17.0.2" 2022-01-18
OpenJDK Runtime Environment (build 17.0.2+8-86)
OpenJDK 64-Bit Server VM (build 17.0.2+8-86, mixed mode, sharing)
[centos@localhost uat_services]$ echo $JAVA_HOME
/home/centos/apps/jdk-17.0.2

About using classpath inside the dependency, I don't build the shared script/properties files to a jar, so I don't know how to set it as a folder.
Is it possible for using classpath dependency with folder?

Thanks,
Truong Nguyen.

On Fri, Jul 14, 2023 at 2:32 PM S. Ali Tokmen <nos...@alishomepage.com> wrote:
Hi Truong

Unsupported class file major version 61 means the JVM you're using is too old, 61 is the bytecode version for Java 17.

I'm unsure if you saw my other note, https://codehaus-cargo.github.io/cargo/Application+Classpath.html might be easier that the -cp options.
On 14 Jul 2023 08:52, Nguyen Xuan Truong <nxtru...@gmail.com> wrote:
Hi Ali,

I use the START_JVMARGS as below:
<container>
    <timeout>2980000</timeout>
    <containerId>jetty10x</containerId>
    <artifactInstaller>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-distribution</artifactId>
        <version>10.0.0.beta1</version>
    </artifactInstaller>
    <systemProperties>
        <greenmail.auth.disabled>true</greenmail.auth.disabled>
        <START_JVMARGS>-cp ${basedir}/target/test-classes/ -cp ${basedir}/src/robot/shared/classes/</START_JVMARGS>
    </systemProperties>
</container>

But I got the error about "Unsupported class file major version 61".

I also attached the full stack trace for the location tag and classpath in the attachment.

Please check them and let me know if you found something.

Thanks,
Truong Nguyen.

On Fri, Jul 14, 2023 at 12:34 PM S. Ali Tokmen <nos...@alishomepage.com> wrote:

Hi Truong

That is an interesting use case! Firat time I see the usage of paths in dependency elements, the typical has been to use JARs. Can you please share the full stack trace?

Anyhow, to your case: you could also use the GeneralPropertySet.JVMARGS and GeneralPropertySet.START_JVMARGS container properties with a -classpath (or -cp) argument to have the associated classpath elements added to the container JVM's classpath.

Regarda



--
Impossible = I'm possible!!!



--
Impossible = I'm possible!!!

Nguyen Xuan Truong

unread,
Jul 14, 2023, 7:15:11 AM7/14/23
to codehau...@googlegroups.com
Hi Ali,

Thanks a lot for your time that spend to help me. But I really need your help, again :)

Actually, I read the example for the Application Classpath but still did not figure out how to apply it to my case.

So I will attach my pom here, could you please help to check and point me out what I should do?

I also set the cargo.java.home but still got the Java version error.

Thanks and Regards,
Truong Nguyen.

pom_error.xml

S. Ali Tokmen

unread,
Jul 14, 2023, 12:08:20 PM7/14/23
to Codehaus Cargo

Hi Nguyen

This is indeed simpler, attached is my fix proposal.

Can younalso run a mvn -version and check what JDK is used?

pom_error.xml

Truong Nguyen Xuan

unread,
Jul 19, 2023, 1:26:19 PM7/19/23
to Codehaus Cargo
Hi Ali,

Sorry for the late response.

I have applied the classpath as your proposal but still got the same issue.

Here is the maven --version result:
Maven home: /home/centos/apps/apache-maven-3.8.8
Java version: 17.0.2, vendor: Oracle Corporation, runtime: /home/centos/apps/jdk-17.0.2
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1160.66.1.el7.x86_64", arch: "amd64", family: "UNIX"

It used the java version 17, so it's ok for the maven's jdk.

And I saw that the error has come from the asm library, here is the full stack trace:
Suppressed:
|java.lang.RuntimeException: Error scanning entry com/commons/utils/zip/ZippedContentInfo.class from jar file:///tmp/jetty-0_0_0_0-8181-docrepo-acl_war-_docrepo-acl-any-16167591140399766461.dir/webapp/WEB-INF/lib/zip--20230711.100422-20.jar
| at org.eclipse.jetty.annotations.AnnotationParser.lambda$parseJar$0(AnnotationParser.java:868)
| at java.base/java.util.TreeMap$ValueSpliterator.forEachRemaining(TreeMap.java:3215)
| at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)
| at org.eclipse.jetty.annotations.AnnotationParser.parseJar(AnnotationParser.java:860)
| at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:761)
| at org.eclipse.jetty.annotations.AnnotationConfiguration$ParserTask.call(AnnotationConfiguration.java:172)
| at org.eclipse.jetty.annotations.AnnotationConfiguration$1.run(AnnotationConfiguration.java:465)
| at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:823)
| at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:945)
| at java.base/java.lang.Thread.run(Thread.java:833)
|Caused by:
|java.lang.IllegalArgumentException: Unsupported class file major version 61
| at org.objectweb.asm.ClassReader.<init>(ClassReader.java:196)
| at org.objectweb.asm.ClassReader.<init>(ClassReader.java:177)
| at org.objectweb.asm.ClassReader.<init>(ClassReader.java:163)
| at org.objectweb.asm.ClassReader.<init>(ClassReader.java:284)
| at org.eclipse.jetty.annotations.AnnotationParser.scanClass(AnnotationParser.java:920)
| at org.eclipse.jetty.annotations.AnnotationParser.parseJarEntry(AnnotationParser.java:905)
| at org.eclipse.jetty.annotations.AnnotationParser.lambda$parseJar$0(AnnotationParser.java:864)
| at java.base/java.util.TreeMap$ValueSpliterator.forEachRemaining(TreeMap.java:3215)
| at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)
| at org.eclipse.jetty.annotations.AnnotationParser.parseJar(AnnotationParser.java:860)
| at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:761)
| at org.eclipse.jetty.annotations.AnnotationConfiguration$ParserTask.call(AnnotationConfiguration.java:172)
| at org.eclipse.jetty.annotations.AnnotationConfiguration$1.run(AnnotationConfiguration.java:465)
| at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:823)
| at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:945)
| at java.base/java.lang.Thread.run(Thread.java:833)
Caused by:
java.lang.RuntimeException: Error scanning file /tmp/jetty-0_0_0_0-8181-docrepo-ac_war-_docrepo-acl-any-16167591140399766461.dir/webapp/WEB-INF/classes/com/docrepoacl/task/DeploymentExecutor.class
at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:826)
at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:754)
at org.eclipse.jetty.annotations.AnnotationConfiguration$ParserTask.call(AnnotationConfiguration.java:172)
at org.eclipse.jetty.annotations.AnnotationConfiguration$1.run(AnnotationConfiguration.java:465)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:823)
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:945)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by:
java.lang.IllegalArgumentException: Unsupported class file major version 61
at org.objectweb.asm.ClassReader.<init>(ClassReader.java:196)
at org.objectweb.asm.ClassReader.<init>(ClassReader.java:177)
at org.objectweb.asm.ClassReader.<init>(ClassReader.java:163)
at org.objectweb.asm.ClassReader.<init>(ClassReader.java:284)
at org.eclipse.jetty.annotations.AnnotationParser.scanClass(AnnotationParser.java:920)
at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:819)
at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:754)
at org.eclipse.jetty.annotations.AnnotationConfiguration$ParserTask.call(AnnotationConfiguration.java:172)
at org.eclipse.jetty.annotations.AnnotationConfiguration$1.run(AnnotationConfiguration.java:465)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:823)
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:945)
at java.base/java.lang.Thread.run(Thread.java:833)
2023-07-19 17:13:37.022:INFO :oejs.AbstractConnector:main: Started ServerConnector@cb191ca{HTTP/1.1, (http/1.1, h2c)}{0.0.0.0:8181}
2023-07-19 17:13:37.027:INFO :oejs.Server:main: Started mailto:server@5656be13{starting}[10.0.0.beta1,sto=5000] @2205ms

I have check that the  org.objectweb.asm.ClassReader is built with the very old jdk (1.2 for asm 3.1, and 1.5 for the latest one 9.5). Seem like it doesn't work with the class that built with jdk17.

Could you please check to confirm this?

Thanks,
Truong Nguyen.

S. Ali Tokmen

unread,
Jul 19, 2023, 2:23:40 PM7/19/23
to codehau...@googlegroups.com

Hi Truong

Thank you for the detailed stack trace.

I noticed that you are selecting Jetty 10 beta 1 - Which is over 3 years old, and is a first beta (hence full of bugs). Do you really want to pursue that way, may I suggest to change it to 10.0.15 (latest version)?

On 19/07/2023 19:26, Truong Nguyen Xuan wrote:
Hi Ali,

Can you also run a mvn -version and check what JDK is used?

Nguyen Xuan Truong

unread,
Jul 20, 2023, 12:36:04 AM7/20/23
to codehau...@googlegroups.com
Yes, it works for me now.

Thanks a lot for your help, Ali.

Just one more question, I see that the log was printed to the file, could I configure it to print to the console?

Thanks,
Truong Nguyen.

S. Ali Tokmen

unread,
Jul 21, 2023, 9:31:40 AM7/21/23
to codehau...@googlegroups.com

Hi Truong

Excellent news! Perhaps for the sake of code cleanliness, you could also remove the JVM path that was added - So it doesn't cause confusions in the future.

Changing log parameters would be done following the instructions on https://eclipse.dev/jetty/documentation/jetty-10/operations-guide/index.html#og-server-logging-server (to specify the associated configuration files for logging the way you need) and https://codehaus-cargo.github.io/cargo/Configuration+files+option.html (to add them to the Jetty container configuration). When there is demand, we could also think of having the feature to choose to have the logs in the console as a Codehaus Cargo Jetty container configuration option, and would welcome contributions.

S. Ali Tokmen

unread,
Jul 21, 2023, 9:58:53 AM7/21/23
to codehau...@googlegroups.com

Hi Truong

Actually - This is simpler than I explained: simply change the cargo.jetty.modules configuration property, and have it without console-capture. In other words, you'd set it to: server,http,http2c,annotations,plus,websocket,jsp,ext,deploy

Reply all
Reply to author
Forward
0 new messages