1

We have a Guice based web application that we deploy to JBoss EAP 6.4.0. This application uses Netflix Governator library, which provides support for the PostConstruct annotation.

This application starts without any problem on JBoss, until we add some JAAS configuration files provided by our client. With those files, the application does not start and throws this exception:

JBWEB000287: Exception sending context initialized event to listener instance of class c.n.b.s.ServletContextListener: java.lang.NoClassDefFoundError: javax/annotation/PostConstruct

I fixed the issue by adding this dependency:

<dependency>
    <groupId>javax.annotation</groupId>
    <artifactId>javax.annotation-api</artifactId>
    <version>1.3.1</version>
 </dependency>

But I am wondering if it's the correct solution. I am not familiar with JBoss nor JAAS and I was wondering if it shouldn't be fixed in a better way, in a module configuration for instance. I do not understand why I don't have this error all the time, but only with the JAAS XML files.

1 Answers1

0

JBoss already provides the library, so you should change the scope to provided. If you would like to use all libraries from JBoss, you can add a dependency:

    <dependency>
        <groupId>org.jboss.spec</groupId>
        <artifactId>jboss-javaee-6.0</artifactId>
        <type>pom</type>
    </dependency>
awagenhoffer
  • 261
  • 1
  • 4
  • 13
  • Our application can be deployed to other application servers or servlet containers so I won't use this dependency. I will try with the scope "compileOnly" (I am actually using Gradle). So you confirm that packaging the dependency is the way to go? Any idea why the problem appears only with JAAS configuration files? – Guillaume Lucazeau Jan 15 '18 at 14:57
  • That's what I thought, with "compileOnly" Gradle scope, I have the same issue. I really have to package the annotations to get rid of it. I really don't know why this happens only with JAAS configuration files. – Guillaume Lucazeau Jan 16 '18 at 12:32
  • Sorry, I haven't used Gradle yet, but compileOnly seems to like provided in Maven. Can you list your dependencies (gradle dependencies) like mvn:tree? Is the javax.annotation-api there? or in your WAR/EAR? – awagenhoffer Jan 17 '18 at 09:16