the.wizard
the.wizard

Reputation: 1109

ClassNotFoundException org.reflections.Configuration When Using Optaplanner 7.0.0.Final

I was develop an application that use Optaplanner 7.0.0.Final. Here is my pom.xml content:

<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.intestech</groupId>
<artifactId>resourcePlanner</artifactId>
<version>0.0.1-SNAPSHOT</version>

<properties>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.test.skip>true</maven.test.skip>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.optaplanner</groupId>
            <artifactId>optaplanner-bom</artifactId>
            <type>pom</type>
            <version>7.0.0.Final</version>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <!-- MSSQL JDBC API -->
    <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>mssql-jdbc</artifactId>
        <version>6.1.2.jre8-preview</version>
    </dependency>
    <!-- Hibernate Core API -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.3.11.Final</version>
    </dependency>
    <!-- JUnit Test API -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>
    <!-- Optaplanner API -->
    <dependency>
        <groupId>org.optaplanner</groupId>
        <artifactId>optaplanner-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.optaplanner</groupId>
        <artifactId>optaplanner-benchmark</artifactId>
    </dependency>
    <dependency>
        <groupId>org.kie</groupId>
        <artifactId>kie-api</artifactId>
        <version>7.0.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-decisiontables</artifactId>
        <version>7.0.0.Final</version>
        <scope>runtime</scope>
    </dependency>
    <!-- External dependencies -->
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.5</version>
    </dependency>
    <!-- Common utils -->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.4</version>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>18.0</version>
    </dependency>
    <!-- Logging -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.7</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.1.3</version>
        <scope>runtime</scope>
    </dependency>
    <!-- XML -->
    <dependency>
        <groupId>com.thoughtworks.xstream</groupId>
        <artifactId>xstream</artifactId>
        <version>1.4.9</version>
    </dependency>

    <!-- Examples only dependencies. -->
    <!-- WARNING: every examples only dependency must be properly dealt with 
        in optaplanner-distribution/src/main/assembly/assembly-optaplanner.xml -->
    <!-- Converters -->
    <dependency>
        <groupId>org.jdom</groupId>
        <artifactId>jdom</artifactId>
        <version>1.1.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.15</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.15</version>
        <exclusions>
            <exclusion>
                <!-- Collides with 'javax.xml.stream:stax-api' brought in by 'org.drools:drools-decisiontables'. -->
                <groupId>stax</groupId>
                <artifactId>stax-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

When I tried to run my app, it will reproduce this exception:

Exception in thread "main" java.lang.NoClassDefFoundError: org/reflections/Configuration
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
at java.lang.Class.getDeclaredFields(Class.java:1916)
at com.thoughtworks.xstream.mapper.AnnotationMapper.processTypes(AnnotationMapper.java:204)
at com.thoughtworks.xstream.mapper.AnnotationMapper.processAnnotations(AnnotationMapper.java:164)
at com.thoughtworks.xstream.XStream.processAnnotations(XStream.java:2036)
at com.thoughtworks.xstream.XStream.processAnnotations(XStream.java:2047)
at org.optaplanner.core.impl.solver.XStreamXmlSolverFactory.buildXStream(XStreamXmlSolverFactory.java:54)
at org.optaplanner.core.impl.solver.XStreamXmlSolverFactory.<init>(XStreamXmlSolverFactory.java:73)
at org.optaplanner.core.impl.solver.XStreamXmlSolverFactory.<init>(XStreamXmlSolverFactory.java:65)
at org.optaplanner.core.api.solver.SolverFactory.createFromXmlResource(SolverFactory.java:89)
at com.intestech.resourceplanner.program.Driver.main(Driver.java:31) 
Caused by: java.lang.ClassNotFoundException: org.reflections.Configuration
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 12 more

What could be possible wrong that caused me this error? I tried to investigate it, when I used version 6.5.0.Final, it will pull all the related dependencies. But since version 7.0.0.Final maven only pull the optaplanner-core artifact. Any comments will be appreciated. Thanks and regards.

Update 1

I have try to run mvn:dependency:tree -Dverbose and here is the result :

D:\workspace\UnivTimetabling\resourcePlanner>mvn dependency:tree -Dverbose
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building resourcePlanner 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: https://repo.maven.apache.org/maven2/commons-codec/commons-codec/ma
ven-metadata.xml
Downloaded: https://repo.maven.apache.org/maven2/commons-codec/commons-codec/mav
en-metadata.xml (612 B at 0.1 KB/sec)
[WARNING] The POM for org.optaplanner:optaplanner-core:jar:7.0.0.Final is invali
d, transitive dependencies (if any) will not be available, enable debug logging
for more details
[WARNING] The POM for org.optaplanner:optaplanner-benchmark:jar:7.0.0.Final is i
nvalid, transitive dependencies (if any) will not be available, enable debug log
ging for more details
[WARNING] The POM for org.kie:kie-api:jar:7.0.0.Final is invalid, transitive dep
endencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.drools:drools-decisiontables:jar:7.0.0.Final is invali
d, transitive dependencies (if any) will not be available, enable debug logging
for more details
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ resourcePlanner ---
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-uti
ls/1.5.7/plexus-utils-1.5.7.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
s/1.5.7/plexus-utils-1.5.7.pom (8 KB at 7.5 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-uti
ls/3.0.9/plexus-utils-3.0.9.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
s/3.0.9/plexus-utils-3.0.9.pom (4 KB at 2.5 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-project
/2.0.5/maven-project-2.0.5.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-project/
2.0.5/maven-project-2.0.5.pom (2 KB at 1.6 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-setting
s/2.0.5/maven-settings-2.0.5.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-settings
/2.0.5/maven-settings-2.0.5.pom (2 KB at 2.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-profile
/2.0.5/maven-profile-2.0.5.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-profile/
2.0.5/maven-profile-2.0.5.pom (2 KB at 2.4 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-artifac
t-manager/2.0.5/maven-artifact-manager-2.0.5.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-artifact
-manager/2.0.5/maven-artifact-manager-2.0.5.pom (2 KB at 2.5 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-reposit
ory-metadata/2.0.5/maven-repository-metadata-2.0.5.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-reposito
ry-metadata/2.0.5/maven-repository-metadata-2.0.5.pom (2 KB at 2.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-uti
ls/3.0.9/plexus-utils-3.0.9.jar
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
s/3.0.9/plexus-utils-3.0.9.jar (227 KB at 107.1 KB/sec)
[INFO] artifact commons-codec:commons-codec: checking for updates from central
[WARNING] Failed to build parent project for org.optaplanner:optaplanner:pom:7.0
.0.Final
[WARNING] Failed to build parent project for org.optaplanner:optaplanner-core:bu
ndle:7.0.0.Final
[WARNING] Invalid POM for org.optaplanner:optaplanner-core:jar:7.0.0.Final, tran
sitive dependencies (if any) will not be available, enable debug logging for mor
e details
[WARNING] Failed to build parent project for org.optaplanner:optaplanner:pom:7.0
.0.Final
[WARNING] Failed to build parent project for org.optaplanner:optaplanner-benchma
rk:bundle:7.0.0.Final
[WARNING] Invalid POM for org.optaplanner:optaplanner-benchmark:jar:7.0.0.Final,
 transitive dependencies (if any) will not be available, enable debug logging fo
r more details
[WARNING] Failed to build parent project for org.kie:kie-api-parent:pom:7.0.0.Fi
nal
[WARNING] Failed to build parent project for org.kie:kie-api:bundle:7.0.0.Final
[WARNING] Invalid POM for org.kie:kie-api:jar:7.0.0.Final, transitive dependenci
es (if any) will not be available, enable debug logging for more details
[WARNING] Failed to build parent project for org.drools:drools:pom:7.0.0.Final
[WARNING] Failed to build parent project for org.drools:drools-decisiontables:bu
ndle:7.0.0.Final
[WARNING] Invalid POM for org.drools:drools-decisiontables:jar:7.0.0.Final, tran
sitive dependencies (if any) will not be available, enable debug logging for mor
e details
[INFO] com.intestech:resourcePlanner:jar:0.0.1-SNAPSHOT
[INFO] +- com.microsoft.sqlserver:mssql-jdbc:jar:6.1.2.jre8-preview:compile
[INFO] |  \- com.microsoft.azure:azure-keyvault:jar:0.9.7:compile
[INFO] |     +- com.microsoft.azure:azure-core:jar:0.9.7:compile
[INFO] |     |  +- (org.apache.httpcomponents:httpclient:jar:4.3.6:compile - omi
tted for duplicate)
[INFO] |     |  +- (commons-codec:commons-codec:jar:1.10:compile - omitted for d
uplicate)
[INFO] |     |  +- commons-lang:commons-lang:jar:2.6:compile
[INFO] |     |  +- javax.mail:mail:jar:1.4.5:compile
[INFO] |     |  |  \- javax.activation:activation:jar:1.1:compile
[INFO] |     |  +- (javax.inject:javax.inject:jar:1:compile - omitted for duplic
ate)
[INFO] |     |  +- com.sun.jersey:jersey-client:jar:1.19:compile
[INFO] |     |  |  \- com.sun.jersey:jersey-core:jar:1.19:compile
[INFO] |     |  |     \- javax.ws.rs:jsr311-api:jar:1.1.1:compile
[INFO] |     |  \- com.sun.jersey:jersey-json:jar:1.19:compile
[INFO] |     |     +- org.codehaus.jettison:jettison:jar:1.1:compile
[INFO] |     |     +- com.sun.xml.bind:jaxb-impl:jar:2.2.3-1:compile
[INFO] |     |     |  \- javax.xml.bind:jaxb-api:jar:2.2.2:compile
[INFO] |     |     |     +- javax.xml.stream:stax-api:jar:1.0-2:compile
[INFO] |     |     |     \- (javax.activation:activation:jar:1.1:compile - omitt
ed for duplicate)
[INFO] |     |     +- org.codehaus.jackson:jackson-core-asl:jar:1.9.2:compile
[INFO] |     |     +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.2:compile
[INFO] |     |     |  \- (org.codehaus.jackson:jackson-core-asl:jar:1.9.2:compil
e - omitted for duplicate)
[INFO] |     |     +- org.codehaus.jackson:jackson-jaxrs:jar:1.9.2:compile
[INFO] |     |     |  +- (org.codehaus.jackson:jackson-core-asl:jar:1.9.2:compil
e - omitted for duplicate)
[INFO] |     |     |  \- (org.codehaus.jackson:jackson-mapper-asl:jar:1.9.2:comp
ile - omitted for duplicate)
[INFO] |     |     +- org.codehaus.jackson:jackson-xc:jar:1.9.2:compile
[INFO] |     |     |  +- (org.codehaus.jackson:jackson-core-asl:jar:1.9.2:compil
e - omitted for duplicate)
[INFO] |     |     |  \- (org.codehaus.jackson:jackson-mapper-asl:jar:1.9.2:comp
ile - omitted for duplicate)
[INFO] |     |     \- (com.sun.jersey:jersey-core:jar:1.19:compile - omitted for
 duplicate)
[INFO] |     +- org.apache.httpcomponents:httpclient:jar:4.3.6:compile
[INFO] |     |  +- org.apache.httpcomponents:httpcore:jar:4.3.3:compile
[INFO] |     |  +- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] |     |  \- (commons-codec:commons-codec:jar:1.6:compile - omitted for co
nflict with 1.10)
[INFO] |     +- javax.inject:javax.inject:jar:1:compile
[INFO] |     \- com.microsoft.azure:adal4j:jar:1.0.0:compile
[INFO] |        +- com.nimbusds:oauth2-oidc-sdk:jar:4.5:compile
[INFO] |        |  +- (javax.mail:mail:jar:1.4.7:compile - omitted for conflict
with 1.4.5)
[INFO] |        |  +- net.jcip:jcip-annotations:jar:1.0:compile
[INFO] |        |  +- (org.apache.commons:commons-lang3:jar:3.3.1:compile - omit
ted for conflict with 3.4)
[INFO] |        |  +- (commons-codec:commons-codec:jar:1.9:compile - omitted for
 conflict with 1.10)
[INFO] |        |  +- net.minidev:json-smart:jar:1.1.1:compile
[INFO] |        |  +- com.nimbusds:lang-tag:jar:1.4:compile
[INFO] |        |  |  \- (net.minidev:json-smart:jar:1.1.1:compile - omitted for
 duplicate)
[INFO] |        |  \- com.nimbusds:nimbus-jose-jwt:jar:3.1.2:compile
[INFO] |        |     +- (net.jcip:jcip-annotations:jar:1.0:compile - omitted fo
r duplicate)
[INFO] |        |     +- (net.minidev:json-smart:jar:1.1.1:compile - omitted for
 duplicate)
[INFO] |        |     \- org.bouncycastle:bcprov-jdk15on:jar:1.51:compile
[INFO] |        +- com.google.code.gson:gson:jar:2.2.4:compile
[INFO] |        +- (org.slf4j:slf4j-api:jar:1.7.5:compile - omitted for conflict
 with 1.7.7)
[INFO] |        \- (commons-codec:commons-codec:jar:1.10:compile - omitted for d
uplicate)
[INFO] +- org.hibernate:hibernate-core:jar:4.3.11.Final:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
[INFO] |  +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile

[INFO] |  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar
:1.0.0.Final:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] |  +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.5.Final:
compile
[INFO] |  |  +- (org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile - omitted
for duplicate)
[INFO] |  |  \- (org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:com
pile - omitted for duplicate)
[INFO] |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Fin
al:compile
[INFO] |  +- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  \- org.jboss:jandex:jar:1.1.0.Final:compile
[INFO] +- junit:junit:jar:4.12:compile
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:compile
[INFO] +- org.optaplanner:optaplanner-core:jar:7.0.0.Final:compile
[INFO] +- org.optaplanner:optaplanner-benchmark:jar:7.0.0.Final:compile
[INFO] +- org.kie:kie-api:jar:7.0.0.Final:compile
[INFO] +- org.drools:drools-decisiontables:jar:7.0.0.Final:runtime
[INFO] +- commons-io:commons-io:jar:2.5:compile
[INFO] +- org.apache.commons:commons-lang3:jar:3.4:compile
[INFO] +- com.google.guava:guava:jar:18.0:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.7:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.1.3:runtime
[INFO] |  +- ch.qos.logback:logback-core:jar:1.1.3:runtime
[INFO] |  \- (org.slf4j:slf4j-api:jar:1.7.7:runtime - omitted for duplicate)
[INFO] +- com.thoughtworks.xstream:xstream:jar:1.4.9:compile
[INFO] |  +- xmlpull:xmlpull:jar:1.1.3.1:compile
[INFO] |  \- xpp3:xpp3_min:jar:1.1.4c:compile
[INFO] +- org.jdom:jdom:jar:1.1.3:compile
[INFO] +- org.apache.poi:poi:jar:3.15:compile
[INFO] |  +- commons-codec:commons-codec:jar:1.10:compile
[INFO] |  \- org.apache.commons:commons-collections4:jar:4.1:compile
[INFO] \- org.apache.poi:poi-ooxml:jar:3.15:compile
[INFO]    +- (org.apache.poi:poi:jar:3.15:compile - omitted for duplicate)
[INFO]    +- org.apache.poi:poi-ooxml-schemas:jar:3.15:compile
[INFO]    |  \- org.apache.xmlbeans:xmlbeans:jar:2.6.0:compile
[INFO]    \- com.github.virtuald:curvesapi:jar:1.04:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 47.364 s
[INFO] Finished at: 2017-08-26T06:05:48+07:00
[INFO] Final Memory: 16M/134M
[INFO] ------------------------------------------------------------------------

I see some warnings there, could it be what causing this problem? How to resolve it?

Upvotes: 0

Views: 4443

Answers (1)

Geoffrey De Smet
Geoffrey De Smet

Reputation: 27312

When the red engine light is blinking, stop driving the car and fix the problem.

java.lang.NoClassDefFoundError: org/reflections/Configuration

That class org.reflections.Configuration comes from the reflections.jar which is a transitive dependency of optaplanner-core.

The maven build has a big red warning stating that it's not putting transitive deps (such as the reflections jar) on the classpath:

[WARNING] The POM for org.optaplanner:optaplanner-core:jar:7.0.0.Final is invali
d, transitive dependencies (if any) will not be available, enable debug logging
for more details

Not sure why the optaplanner-core 7.0.0.Final pom is invalid - I haven't seen that anywhere else and we have a lot of users using it every day, so it's probably just on your system. Delete ~/.m2/repository.

Upvotes: 1

Related Questions