Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NoClassDefFoundError: org/testcontainers/utility/PathUtils #37

Open
avasenin opened this issue Dec 11, 2023 · 5 comments
Open

Comments

@avasenin
Copy link

Version of plugin 0.0.3
Version of jooq: 3.18.7
Version of testcontainers: 1.19.3

This error appeared all the time, even in case of successful runs.

Can be related to testcontainers/testcontainers-java#1454

Exception in thread "Thread-5" java.lang.NoClassDefFoundError: org/testcontainers/utility/PathUtils
	at org.testcontainers.utility.MountableFile.lambda$deleteOnExit$0(MountableFile.java:318)
	at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.ClassNotFoundException: org.testcontainers.utility.PathUtils
	at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
	... 2 more
	
@SightStudio
Copy link

testcontainers/testcontainers-java#1454
this issue is not solved. should be reopened. :(

@oxygenecore
Copy link

Does it even work?
testcontainers/testcontainers-java#1454 (comment)

Hmm, I'm not really sure if we can help much with this. Running Testcontainers code directly from a Maven plugin isn't something we've attempted to support, as we're more focused on testing. I assume your usage scenarios are not testing?

As you say it does look like the Maven classloader closing is what's causing it. If that's Maven's classloader behaviour then I imagine shutdown hooks are essentially not safe inside of a Maven plugin, and should be avoided.

If there's something simple that we could change then I think we could accept a PR, but otherwise I'm afraid we might have to chalk this up as an unsupported use case. Sorry to disappoint.

Looks like this plugin is not supported by the authors from the same organization... do I not understand something?

@oxygenecore
Copy link

oxygenecore commented Mar 6, 2024

(this relates both to testcontainers-java and to this maven plugin, so posting here as well)

This is what Maven documentation states:
https://maven.apache.org/plugin-developers/common-bugs.html#using-shutdown-hooks

The problem is that the JVM executing Maven can be running much longer than the actual Maven build. Of course, this does not apply to the standalone invocation of Maven from the command line. However, it affects the embedded usage of Maven in IDEs or CI servers. In those cases, the cleanup tasks will be deferred, too. If the JVM is then executing a bunch of other Maven builds, many such cleanup tasks can sum up, eating up resources of the JVM.

For this reason, plugin developers should avoid usage of shutdown hooks and rather use try/finally blocks to perform cleanup as soon as the resources are no longer needed.

So, I guess, the maven plugin should clean up the shutdown hooks created by testcontainers-java?
Or rather - remove them from the shutdown hooks and execute them in finally block?

@MixFr
Copy link

MixFr commented Mar 19, 2024

Any news here?

I get the same error with MYSQL, followed the official guide:
testcontainers-jooq-codegen-maven-plugin-guide

Exception in thread "Thread-5" java.lang.NoClassDefFoundError: org/testcontainers/utility/PathUtils at org.testcontainers.utility.MountableFile.lambda$deleteOnExit$0(MountableFile.java:318) at java.base/java.lang.Thread.run(Thread.java:833) Caused by: java.lang.ClassNotFoundException: org.testcontainers.utility.PathUtils at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50) at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239) ... 2 more

@kiview
Copy link
Member

kiview commented Apr 25, 2024

@oxygenecore The comment you quoted from testcontainers/testcontainers-java#1454 is from 2019, it significantly predates the creation of this plugin and hence is not related with regards to org not supporting this plugin. However, the technical investigation is of course related.

@sivaprasadreddy is the author of this plugin. I don't know if this exception (maybe originating from executing of the shutdown hook) is really an issue in the context of this use case (which file are we supposed to delete?). Can we technically remove the shutdown hook from within the plugin?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants