Phyxx
Phyxx

Reputation: 16086

Weld "Enclosing method not found" exception in an EJB JAR

Deploying an EJB Jar to WildFly 8.2.0 with CDI enabled (i.e. with a minimal beans.xml file) is leading to "Enclosing method not found" exceptions being thrown. There is nothing particularly useful in the logs to identify the source of the error. How do I fix this?

Upvotes: 2

Views: 2428

Answers (2)

Michael
Michael

Reputation: 3256

In my case I got this error when starting an app from Intellij Idea.

It happened suddenly in an app that worked. Using the debugger I could see that it looked for a method that I have deleted recently. The method was not in use.

The solution was to run mvn clean

Upvotes: 0

Phyxx
Phyxx

Reputation: 16086

This was because my EJB Jar was being created by Gradle as a "Fat" jar i.e.

task fatJar(type: Jar) {
    baseName = project.name + '-all'
    from {
        configurations.compile
            .collect {
                println it
                it.isDirectory() ? it : zipTree(it)
            }
    }
    with jar
}

I also had these artifacts referenced in order to get access to the Java EE libraries I needed:

compile 'javax:javaee-api:7.0'
compile 'javax:javaee-web-api:7.0'
compile 'javax.jms:jms:1.1'

The problem was that these Javax libraries were being pulled into the JAR, which was unnecessary because Wildfly already provides them. The duplication was causing the Weld exception.

The solution was to exclude these Javax libraries from the Fat JAR:

task fatJar(type: Jar) {
    baseName = project.name + '-all'
    from {
        configurations.compile
            /*
                Effectively the javax libraries are provided in scope,
                so don't add them to the jar. Failing to exclude these
                leads to Weld CDI exceptions like
             */
            .findAll {
                it.toString().indexOf('javax') == -1
            }
            .collect {
                println it
                it.isDirectory() ? it : zipTree(it)
            }
    }
    with jar
}

With this change, the exceptions went away.

Upvotes: 1

Related Questions