Home > other >  How to solve a Camel3 fat-jar creation exception?
How to solve a Camel3 fat-jar creation exception?

Time:10-02

I use Apache Camel 3.18.2 witch camel-main. To create a fat-jar I configured the following two plugins within my pom.xml:

  <plugin>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-maven-plugin</artifactId>
    <version>3.18.2</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>prepare-fatjar</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
  
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
      <archive>
        <manifest>
          <mainClass>de.powerstat.camel.homeautomation.MainApp</mainClass>
        </manifest>
      </archive>
    </configuration>
    <executions>
      <execution>
        <id>make-assembly</id>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

As dependecies I have:

<dependencies>
  <dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-core</artifactId>
  </dependency>

  <dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-main</artifactId>
  </dependency>

  <dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-test</artifactId>
    <scope>test</scope>
  </dependency>

  <dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-netty</artifactId>
  </dependency>

  <dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-stream</artifactId>
  </dependency>

  <dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-paho</artifactId>
  </dependency>

  <dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-quartz</artifactId>
  </dependency>

  <dependency>
     <groupId>de.powerstat.camel.component</groupId>
     <artifactId>camel-fbaha</artifactId>
    <version>1.0-SNAPSHOT</version>
  </dependency>

  <dependency>
     <groupId>de.powerstat.camel.component</groupId>
     <artifactId>camel-fbtr64</artifactId>
    <version>1.0-SNAPSHOT</version>
  </dependency>

  <dependency>
    <groupId>org.openmuc</groupId>
    <artifactId>jsml</artifactId>
    <version>1.1.2</version>
  </dependency>

  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>2.18.0</version>
    <scope>runtime</scope>
  </dependency>

  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.18.0</version>
    <scope>runtime</scope>
  </dependency>

  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-slf4j-impl</artifactId>
    <version>2.18.0</version>
    <scope>runtime</scope>
  </dependency>

</dependencies>

But durin running mvn clean install I got:

[INFO] --- camel-maven-plugin:3.18.2:prepare-fatjar (default) @ myhome ---
[INFO] Found 5 Camel type converter loaders from project classpath
[INFO]
[INFO] --- maven-assembly-plugin:2.2-beta-5:single (make-assembly) @ myhome ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5:single (make-assembly) on project myhome: Error reading assemblies: No assembly descriptors found. -> [Help 1]

[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Exception in thread "ivy-httpclient-shutdown-handler" java.lang.NoClassDefFoundError: 
org/apache/http/impl/conn/PoolingHttpClientConnectionManager$2
  at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.shutdown(PoolingHttpClientConnectionManager.java:413)
  at org.apache.http.impl.client.HttpClientBuilder$2.close(HttpClientBuilder.java:1244)
  at org.apache.http.impl.client.InternalHttpClient.close(InternalHttpClient.java:201)
  at org.apache.ivy.util.url.HttpClientHandler.close(HttpClientHandler.java:357)
  at org.apache.ivy.util.url.HttpClientHandler$1.run(HttpClientHandler.java:84)
  at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.ClassNotFoundException: org.apache.http.impl.conn.PoolingHttpClientConnectionManager$2
  at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
  at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
  at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
  at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
  ... 6 more

That looks to me like this is an implicit dependency that have not been added by the camel-maven-plugin.

So my question is how to solve this problem?

I also tried to use the maven-shade-plugin instead of maven-assembly-plugin:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.4.0</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <createDependencyReducedPom>true</createDependencyReducedPom>
          <filters>
            <filter>
              <artifact>*:*</artifact>
              <excludes>
                <exclude>META-INF/*.SF</exclude>
                <exclude>META-INF/*.DSA</exclude>
                <exclude>META-INF/*.RSA</exclude>
              </excludes>
            </filter>
          </filters>
        </configuration>
      </execution>
    </executions>
  </plugin>

Which then results in a fat-jar with the following exception during executing it:

[ERROR] 2022-09-30T22:04:48,426 15612/22 org.apache.camel.processor.errorhandler.DefaultErrorHandler Failed delivery for (MessageId: 
08B251E5AD78E72-0000000000000000 on ExchangeId: 
08B251E5AD78E72-0000000000000000). Exhausted after     
delivery attempt: 1 caught: 
org.apache.camel.InvalidPayloadException: No body available of type: java.lang.Integer but has type: 
java.lang.String on: Message. Caused by: No type converter available to convert from type: java.lang.String to the required type: java.lang.Integer. Exchange[]. Caused by: 
[org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: 
java.lang.String to the required type: java.lang.Integer]

So it looks the shade-plugin creates a fat-jar but missed something of camels dependencies.

Maybe this could be solved in one or the other way?

Last but not least the main question is how to create a Camel3 fat jar that is complete and works correctly?

CodePudding user response:

Based on the error message

Error reading assemblies: No assembly descriptors found.

It looks like you are missing your assembly descriptor. You'll need to define a descriptor or descriptorRef

descriptor example:

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.4.2</version>
        <configuration>
          <descriptors>
            <descriptor>src/assembly/src.xml</descriptor>
          </descriptors>
        </configuration>
        [...]
</project>

descriptorRef example:

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <!-- NOTE: We don't need a groupId specification because the group is
             org.apache.maven.plugins ...which is assumed by default.
         -->
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.4.2</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
        [...]
</project>

If defining a descriptor, see the this about the descriptor format.

  • Related