javamavenpom.xml

NoClassDefFound Could not initialize class org.appformer.maven.integration.embedder.MavenSettings$SettingsHolder


When I upgraded the dependency org.codehaus.plexus:plexus-utils from 3.5.1 to 4.0.1, I started getting the error below when the method kieBuilder.buildAll(); gets executed.

Error:

NoClassDefFound Could not initialize class org.appformer.maven.integration.embedder.MavenSettings$SettingsHolder
Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.NoClassDefFoundError: org/codehaus/plexus/util/xml/pull/XmlPullParserException

pom.xml:

<dependency>
    <groupId>org.codehaus.plexus</groupId>
    <artifactId>plexus-utils</artifactId>
    <version>4.0.1</version>
</dependency>
<dependency>
    <groupId>org.codehaus.janino</groupId>
    <artifactId>janino</artifactId>
    <version>3.1.12</version>
</dependency>
<dependency>
    <groupId>org.kie</groupId>
    <artifactId>kie-api</artifactId>
    <version>7.73.0.Final</version>
</dependency>
<dependency>
    <groupId>org.kie</groupId>
    <artifactId>kie-ci</artifactId>
    <version>7.73.0.Final</version>
</dependency>
<dependency>
    <groupId>org.kie</groupId>
    <artifactId>kie-internal</artifactId>
    <version>7.73.0.Final</version>
</dependency>

Java Code:

@Service
public class MyClass {
    private KieServices kieServices;

    @PostConstruct
    public void init() {
        kieServices = KieServices.get();
    }

    private KieBuilder build(String namespace, String ruleSet, String content) {
        KieFileSystem kieFileSystem = kieServices
                .newKieFileSystem()
                .generateAndWritePomXML(generateReleaseId(namespace, ruleSet))
                .write("src/main/resources/" + UUID.randomUUID() + "/ruleset.drl", content);
    
        KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
    
        kieBuilder.buildAll();
    
        return kieBuilder;
    }

    private ReleaseId generateReleaseId(String namespace, String ruleSet) {
        return kieServices.newReleaseId(namespace, ruleSet, "1");
    }
}

Any idea why I started getting this error?


Solution

  • Try to add this dependency to your maven pom:

    <dependency>
        <groupId>org.codehaus.plexus</groupId>
        <artifactId>plexus-xml</artifactId>
        <version>4.0.4</version>
    </dependency>
    

    This adds the Plexus XML Utils to your dependencies.