Uploaded image for project: 'Thorntail'
  1. Thorntail
  2. THORN-614

Container provided dependencies cannot be declared as such for WAR

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 2016.8
    • Fix Version/s: 2016.9
    • Component/s: None
    • Labels:
      None
    • Steps to Reproduce:
      Hide

      To demonstrate the problem I modified example-camel-jpa to have a dependency on Google Gson package and instantiate a class from there just to cause the error:

       camel/camel-jpa/pom.xml                                             | 6 ++++++
       .../java/org/wildfly/swarm/examples/camel/jpa/JpaRouteBuilder.java  | 5 +++++
       config-options/cdi-injection/pom.xml                                | 0
       3 files changed, 11 insertions(+)
      
      diff --git a/camel/camel-jpa/pom.xml b/camel/camel-jpa/pom.xml
      index c53caef..bdd5ace 100644
      --- a/camel/camel-jpa/pom.xml
      +++ b/camel/camel-jpa/pom.xml
      @@ -48,6 +48,12 @@
             <groupId>com.h2database</groupId>
             <artifactId>h2</artifactId>
           </dependency>
      +	<!-- Dummy just to show issue with classloading -->
      +	<dependency>
      +		<groupId>com.google.code.gson</groupId>
      +		<artifactId>gson</artifactId>
      +		<version>2.7</version>
      +	</dependency>
         </dependencies>
       
         <build>
      diff --git a/camel/camel-jpa/src/main/java/org/wildfly/swarm/examples/camel/jpa/JpaRouteBuilder.java b/camel/camel-jpa/src/main/java/org/wildfly/swarm/examples/camel/jpa/JpaRouteBuilder.java
      index afa3f00..cbfc051 100644
      --- a/camel/camel-jpa/src/main/java/org/wildfly/swarm/examples/camel/jpa/JpaRouteBuilder.java
      +++ b/camel/camel-jpa/src/main/java/org/wildfly/swarm/examples/camel/jpa/JpaRouteBuilder.java
      @@ -33,6 +33,9 @@ import org.springframework.transaction.jta.JtaTransactionManager;
       import org.wildfly.extension.camel.CamelAware;
       import org.wildfly.swarm.examples.camel.jpa.model.Customer;
       
      +import com.google.gson.Gson;
      +import com.google.gson.GsonBuilder;
      +
       @CamelAware
       @ApplicationScoped
       public class JpaRouteBuilder extends RouteBuilder {
      @@ -45,6 +48,8 @@ public class JpaRouteBuilder extends RouteBuilder {
       
           @Override
           public void configure() throws Exception {
      +    	// Dummy to show issue with classloading, this will cause a ClassNotFoundException
      +    	Gson gson = new GsonBuilder().create();
           	
               // Configure our JaxbDataFormat to point at our 'model' package
               JaxbDataFormat jaxbDataFormat = new JaxbDataFormat();
      
      Show
      To demonstrate the problem I modified example-camel-jpa to have a dependency on Google Gson package and instantiate a class from there just to cause the error: camel/camel-jpa/pom.xml | 6 ++++++ .../java/org/wildfly/swarm/examples/camel/jpa/JpaRouteBuilder.java | 5 +++++ config-options/cdi-injection/pom.xml | 0 3 files changed, 11 insertions(+) diff --git a/camel/camel-jpa/pom.xml b/camel/camel-jpa/pom.xml index c53caef..bdd5ace 100644 --- a/camel/camel-jpa/pom.xml +++ b/camel/camel-jpa/pom.xml @@ -48,6 +48,12 @@ <groupId>com.h2database</groupId> <artifactId>h2</artifactId> </dependency> + <!-- Dummy just to show issue with classloading --> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <version>2.7</version> + </dependency> </dependencies> <build> diff --git a/camel/camel-jpa/src/main/java/org/wildfly/swarm/examples/camel/jpa/JpaRouteBuilder.java b/camel/camel-jpa/src/main/java/org/wildfly/swarm/examples/camel/jpa/JpaRouteBuilder.java index afa3f00..cbfc051 100644 --- a/camel/camel-jpa/src/main/java/org/wildfly/swarm/examples/camel/jpa/JpaRouteBuilder.java +++ b/camel/camel-jpa/src/main/java/org/wildfly/swarm/examples/camel/jpa/JpaRouteBuilder.java @@ -33,6 +33,9 @@ import org.springframework.transaction.jta.JtaTransactionManager; import org.wildfly.extension.camel.CamelAware; import org.wildfly.swarm.examples.camel.jpa.model.Customer; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + @CamelAware @ApplicationScoped public class JpaRouteBuilder extends RouteBuilder { @@ -45,6 +48,8 @@ public class JpaRouteBuilder extends RouteBuilder { @Override public void configure() throws Exception { + // Dummy to show issue with classloading, this will cause a ClassNotFoundException + Gson gson = new GsonBuilder().create(); // Configure our JaxbDataFormat to point at our 'model' package JaxbDataFormat jaxbDataFormat = new JaxbDataFormat();

      Description

      I first ran into the issue described in SWARM-483 which was caused by duplicate camel jars so the recommended workaround was to use <packagingExcludes> tag to exclude WEB-INF/lib/*.jar when building war.

      However, that has the side effect that other jars that my application depends on are also excluded from the war and then even when they are included in m2repo folder in -swarm.jar and listed in META-INF/wildfly-swarm-application.conf and META-INF/wildfly-swarm-dependencies.conf.

      Duplicate jar's on the classpath is a known source for troubles, hence the normal should be to not have anything in WEB-INF/lib in a war, and instead load the dependencies as listed in META-INF/wildfly-swarm-dependencies.conf to ensure they are present only once.

      After some more investigation I see that I get the same result if I build my application as a jar, dependencies listed in pom.xml and included in the -swarm.jar are not available in the application and causes NoClassDefFoundError.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  bob.mcwhirter Bob McWhirter
                  Reporter:
                  sverker.sverker.abrahamsson.com Sverker Abrahamsson
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  4 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: