2
votes

I am creating JAX-RS application with Apache CXF, Apache Camel and Spring with Maven. When I run the application it is creating an embedded jetty and serving the request.

I want to remove embedded jetty and run it on standalone Tomcat using war file. I tried many suggestions available but not working in my case. Please give any suggestion for the same.

My POMs contains

            <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>2.7.6</version>
            </dependency>

            <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxrs</artifactId>
            <version>2.7.6</version>
            </dependency>

            <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-servlets</artifactId>
            <version>8.1.3.v20120416</version>
            </dependency>

                 <build>
                 <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>8.1.12.v20130726</version>

                <configuration>
                    <scanIntervalSeconds>5</scanIntervalSeconds>
                    <webApp>
                        <contextPath>myfashions</contextPath>
                        <defaultsDescriptor>
                            ${basedir}/src/main/resources/webdefault.xml
                        </defaultsDescriptor>
                    </webApp>
                </configuration>
            </plugin>
            </build>

When I run this using jetty:run with port 8081 from intellij idea , my appplication is starting another embedded jetty server on port 8080 and serving requests.

When I remove all jetty dependencies and plugins and deploy generated WAR in tomcat, I am getting error as

013-09-06_01:21:21 ERROR o.a.c.t.http.HTTPTransportFactory - Cannot find any registered HttpDestinationFactory from the Bus.
Sep 06, 2013 1:21:21 AM org.springframework.web.context.ContextLoader initWebApplicationContext
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'baseApi': Invocation of init method failed; nested exception is org.apache.cxf.service.factory.ServiceConstructionException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1482)

Please suggest a way so that I can genarate WAR which runs inside tomcat without starting embedded jetty.

2

2 Answers

0
votes

Please provide more information regarding what mvn command you use and your POM file.

As per the information provided, I assume you are using "mvn * install". use "mvn clean compile package". Using this, it will only create the WAR file which you can then copy into your tomcat server.

Also, if you don't plan to use JETTY for deployment, you have to exlude them inside your POM, else they will always be present in your classpath. Exclusion sample -

<exclusions>
                <exclusion>
                    <groupId>org.eclipse.jetty</groupId>
                    <artifactId>jetty-continuation</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.eclipse.jetty</groupId>
                    <artifactId>jetty-io</artifactId>
                </exclusion>
</exclusions>

These JARs are included with CXF bundles. Checkout maven exclusion for more details

0
votes

Finally it worked when I removed absolute location from jaxrs-server address configuration and kept relative context path.