Testcontainers-java: java.lang.NoClassDefFoundError after upgrading mysql to 1.11.1

Created on 26 Mar 2019  路  8Comments  路  Source: testcontainers/testcontainers-java

I am creating a MySQLContainer with an init script

public static MySQLContainer mysql = (MySQLContainer) new MySQLContainer().withInitScript("sql/create_schema.sql");

This results in the following exception

Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.StringUtils
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 24 more

This instantiation worked fine on 1.10.7

I checked with Slack and they suggested I report this as the shading changing in 1.11

areshading typbug

Most helpful comment

to sort this completely, I needed to add commons-io as well

    <dependency>
      <groupId>commons-lang</groupId>
      <artifactId>commons-lang</artifactId>
      <version>2.6</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>2.5</version>
      <scope>test</scope>
    </dependency>

All 8 comments

Thanks for reporting!

Meanwhile, you should be able to workaround it by adding 'org.apache.commons:commons-lang3:3.8.1' dependency.

commons lang 3.8.1 doesn't works, commons lang 2.6 is right

<dependency>
    <groupId>commons-lang</groupId>
    <artifactId>commons-lang</artifactId>
    <version>2.6</version>
</dependency>
compile group: 'commons-lang', name: 'commons-lang', version: '2.6'

@robfrank you're right, my bad! 馃憤

to sort this completely, I needed to add commons-io as well

    <dependency>
      <groupId>commons-lang</groupId>
      <artifactId>commons-lang</artifactId>
      <version>2.6</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>2.5</version>
      <scope>test</scope>
    </dependency>

We were able to find the cause and fix it in #1390.
We will try to verify it ourselves, but would appreciate if somebody here can try it with their projects to verify that now it works correctly, with Jitpack or by installing locally.

Switched to:

        <dependency>
            <groupId>com.github.testcontainers</groupId>
            <artifactId>testcontainers-java</artifactId>
            <version>-SNAPSHOT</version>
        </dependency>

image

No more class loader error!

Umm...I don't think that's the right dependency (1.2.1 makes me think so).
Could you please try:

com.github.testcontainers.testcontainers-java:testcontainers:master-SNAPSHOT

and:

com.github.testcontainers.testcontainers-java:mysql:master-SNAPSHOT

Ok second try using master-SNAPSHOT.. still no class loader error!

image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rnorth picture rnorth  路  3Comments

richard77 picture richard77  路  3Comments

chomhanks picture chomhanks  路  3Comments

lovepoem picture lovepoem  路  3Comments

dabraham02124 picture dabraham02124  路  3Comments