You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by sergarci <se...@gmail.com> on 2014/07/17 13:31:56 UTC
Package camel spring into .jar file
Hi everyone
I'm here with a new question about packaging Apache Camel application.
I'm triying to package my application into a jar file. I don't have a custom
main class, I just run camel from spring camel context and it starts all the
routes like this.
/<camelContext xmlns="http://camel.apache.org/schema/spring"
id="camelContext">
<routeContextRef ref="routeOne"/>
</camelContext>/
I'm trying to do just mvn package wich generates one .jar file but when
running with java -jar myApp.jar it cames with "/Failed to load Main-Class
manifest attribute from/".
How can I configure my jar to take my camel spring context as main?
Thanks you all
--
View this message in context: http://camel.465427.n5.nabble.com/Package-camel-spring-into-jar-file-tp5753964.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Package camel spring into .jar file
Posted by Aki Yoshida <el...@gmail.com>.
this is not a camel question and actually it has nothing to do with camel.
you need to look at the maven jar archive plugin documentation.
http://maven.apache.org/shared/maven-archiver/
in your case, take a look at how the Class-Path header in the manifest
file of your jar looks like. You probably have wrong values.
usually you will need to add a few properties (e.g., classpathLayout,
classpathPrefix) in the plugin configuration so that the each path
segment represents a valid class path.
for example, if you want your jar to load dependent jars from your
repo, you can add
<classpathLayoutType>repository</classpathLayoutType>
<classpathPrefix>${settings.localRepository}</classpathPrefix>
and run the build and verify the manifest entry of your generated jar.
regards, aki
2014-07-18 11:03 GMT+02:00 sergarci <se...@gmail.com>:
> I've ended using spring-boot:
>
> /<plugin>
> <groupId>org.springframework.boot</groupId>
> <artifactId>spring-boot-maven-plugin</artifactId>
> <version>1.1.4.RELEASE</version>
> <executions>
> <execution>
> <goals>
> <goal>repackage</goal>
> </goals>
> </execution>
> </executions>
> </plugin>/
>
> With a custom main class:
>
> /import org.apache.camel.spring.Main;
>
> public class CamelMain {
> public static void main(String[] args) throws Exception {
> Main main = new Main();
> main.setApplicationContextUri("spring/camel-context.xml");
> main.enableHangupSupport();
> main.start();
> while (true);
> }
> }/
>
> just running *mvn package* and generated jar file works as if running mvn
> camel:run.
>
> Thanks everyone
>
> Used resources:
> camel in action book
> http://docs.spring.io/spring-boot/docs/1.0.1.RELEASE/reference/html/build-tool-plugins-maven-plugin.html
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Package-camel-spring-into-jar-file-tp5753964p5753993.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Package camel spring into .jar file
Posted by sergarci <se...@gmail.com>.
I've ended using spring-boot:
/<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.1.4.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>/
With a custom main class:
/import org.apache.camel.spring.Main;
public class CamelMain {
public static void main(String[] args) throws Exception {
Main main = new Main();
main.setApplicationContextUri("spring/camel-context.xml");
main.enableHangupSupport();
main.start();
while (true);
}
}/
just running *mvn package* and generated jar file works as if running mvn
camel:run.
Thanks everyone
Used resources:
camel in action book
http://docs.spring.io/spring-boot/docs/1.0.1.RELEASE/reference/html/build-tool-plugins-maven-plugin.html
--
View this message in context: http://camel.465427.n5.nabble.com/Package-camel-spring-into-jar-file-tp5753964p5753993.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Package camel spring into .jar file
Posted by sergarci <se...@gmail.com>.
Hi everyone
I'm doing this but still not working from jar file.
I have a main class like:
/public class CamelMain {
public static void main(String[] args) throws Exception {
String[] filename =
{ "spring/camel-context.xml" };
AbstractXmlApplicationContext spring = new
ClassPathXmlApplicationContext(filename);
spring.start();
Thread.sleep(10000);
spring.stop();
spring.destroy();
}
}/
I use maven jar plugin in my pom like this:
/<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>package.to.main.CamelMain</mainClass>
</manifest>
</archive>
</configuration>
</plugin>/
I can run with *mvn camel:run* I can run main class from Eclipse running as
java application with no problems.
When I do mvn package and try to run with java -jar I have this error:
/C:\Users\garcina\Downloads\workspaces\trunk\dbpost_conversion_ld\target>java
-ja
r myJar.jar
Exception in thread "main" java.lang.NoClassDefFoundError:
org/springframework/c
ontext/support/AbstractXmlApplicationContext
Caused by: java.lang.ClassNotFoundException:
org.springframework.context.support
.AbstractXmlApplicationContext
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: package.to.main.CamelMain. Program w
ill exit./
Is something I'm missing?
Thansk you all
--
View this message in context: http://camel.465427.n5.nabble.com/Package-camel-spring-into-jar-file-tp5753964p5753978.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Package camel spring into .jar file
Posted by sergarci <se...@gmail.com>.
I've also tried with mainClass: org.apache.camel.spring.Main but it also
failed
--
View this message in context: http://camel.465427.n5.nabble.com/Package-camel-spring-into-jar-file-tp5753964p5753972.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Package camel spring into .jar file
Posted by sergarci <se...@gmail.com>.
I think I need something like:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>camel spring context here</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
but I don't knowhow to fill mainClass.
I wak looking this link before but I don't find this:
/Using camel-spring JAR example
This would be similar to the camel-core JAR example, however you would use
the Main class from the org.apache.camel.spring package.
The Main class from camel-spring JAR has many more options and is prepared
for booting Camel from Spring XML files./
I'm I wrong?
--
View this message in context: http://camel.465427.n5.nabble.com/Package-camel-spring-into-jar-file-tp5753964p5753967.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Package camel spring into .jar file
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
See
http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html
And then put your spring xml in the .jar and set the main class in the
manifest, so java -jar know what the main class is.
On Thu, Jul 17, 2014 at 1:31 PM, sergarci <se...@gmail.com> wrote:
> Hi everyone
>
> I'm here with a new question about packaging Apache Camel application.
>
> I'm triying to package my application into a jar file. I don't have a custom
> main class, I just run camel from spring camel context and it starts all the
> routes like this.
>
> /<camelContext xmlns="http://camel.apache.org/schema/spring"
> id="camelContext">
> <routeContextRef ref="routeOne"/>
> </camelContext>/
>
> I'm trying to do just mvn package wich generates one .jar file but when
> running with java -jar myApp.jar it cames with "/Failed to load Main-Class
> manifest attribute from/".
>
> How can I configure my jar to take my camel spring context as main?
>
> Thanks you all
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Package-camel-spring-into-jar-file-tp5753964.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/