Hi,

... I got it working, Andrei. Your hint nailed it.

I got a bit confused, because there was actually a bus-extensions.txt file present in the shaded JAR. But the problem was in fact that there are (I didn't see/know that) multiple META-INF/cxf/bus-extensions.txt files in different CXF dependency JARs. If you don't tell Maven Shade explicitly what to do in such a conflict situation (they all point to the same path in the unified JAR) it will just use (I think) the last one when it merges the dependencies into one JAR.

The solution is similar to the one adopted for the Spring framework (META-INF/spring.schemas, META-INF/spring.handlers)... here's my Maven Shade configuration:

[config]

                <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
                    <version>2.2</version>
                    <configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<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>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                            <configuration>
<minimizeJar>false</minimizeJar>
                                <transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
                                    </transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
                                    </transformer>
                                    <!-- THIS WAS MISSING -->
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/cxf/bus-extensions.txt</resource>
                                    </transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                        <manifestEntries>
<Main-Class>${m11n.project.main}</Main-Class>
<X-Compile-Source-JDK>${maven.compile.source}</X-Compile-Source-JDK>
<X-Compile-Target-JDK>${maven.compile.target}</X-Compile-Target-JDK>
                                        </manifestEntries>
                                    </transformer>
                                </transformers>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

[/config]

Hope it helps if someone is doing a similar thing... works like a charm now :-)

Thanks a ton for the help!

Cheers,

Aleks

On 04.05.2014 09:26, Andrei Shakirin wrote:
Hi,

Normally this stack trace is caused by missing cxf-rt-transports-http-xxx.jar 
on the classpath.
Either the class HTTPTransportFactory.class or META-INF/cxf/bus-extensions.txt 
is not in your jar.

Out of curiosity: what is the reason to compose CXF and Spring in single jar 
using Maven Shade?

Regards,
Andrei.

-----Original Message-----
From: Aleksandar Vidakovic [mailto:[email protected]]
Sent: Sonntag, 4. Mai 2014 01:04
To: [email protected]
Subject: Undertow + CXF + Spring single JAR

Hi,

... I tried to package a CXF project with fairly standard WAR setup (CXFServlet
in web.xml configured) and some additional Spring configuration (nothing
fancy) in a single JAR (with Maven Shade plugin).

99% is working (Undertow is starting, Spring context gets initialized), but CXF
has a problem picking up a transport. I thought that it would just behave the
same way like in a servlet container environment, but apparently something is
missing.

This is the exception that I get:

[console]

Exception in thread "main"
org.springframework.beans.factory.BeanCreationException: Error creating
bean with name
'org.apache.cxf.jaxrs.spring.JAXRSServerFactoryBeanDefinitionParser$SpringJA
XRSServerFactoryBean---72839183':
Invocation of init method failed; nested exception is
org.apache.cxf.service.factory.ServiceConstructionException
       at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFact
ory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
       at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFact
ory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
       at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFact
ory.createBean(AbstractAutowireCapableBeanFactory.java:475)
       at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(
AbstractBeanFactory.java:304)
       at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSi
ngleton(DefaultSingletonBeanRegistry.java:228)
       at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(A
bstractBeanFactory.java:300)
       at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Abstr
actBeanFactory.java:195)
       at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInst
antiateSingletons(DefaultListableBeanFactory.java:703)
       at
org.springframework.context.support.AbstractApplicationContext.finishBeanFac
toryInitialization(AbstractApplicationContext.java:760)
       at
org.springframework.context.support.AbstractApplicationContext.refresh(Abstr
actApplicationContext.java:482)
       at
org.apache.cxf.transport.servlet.CXFServlet.createSpringContext(CXFServlet.jav
a:151)
       at
org.apache.cxf.transport.servlet.CXFServlet.loadBus(CXFServlet.java:74)
       at
org.apache.cxf.transport.servlet.CXFNonSpringServlet.init(CXFNonSpringServlet.
java:76)
       at
io.undertow.servlet.core.ManagedServlet$DefaultInstanceStrategy.start(Manag
edServlet.java:214)
       at
io.undertow.servlet.core.ManagedServlet.createServlet(ManagedServlet.java:1
19)
       at
io.undertow.servlet.core.DeploymentManagerImpl.start(DeploymentManagerI
mpl.java:501)
       at com.hotlabuyo.rest.server.Main.main(Main.java:51)
Caused by: org.apache.cxf.service.factory.ServiceConstructionException
       at
org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.j
ava:205)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
62)
       at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorI
mpl.java:43)
       at java.lang.reflect.Method.invoke(Method.java:483)
       at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFact
ory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1681)
       at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFact
ory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1620)
       at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFact
ory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
       ... 16 more
Caused by: org.apache.cxf.BusException: No DestinationFactory was found for
the namespacehttp://cxf.apache.org/transports/http.
       at
org.apache.cxf.bus.managers.DestinationFactoryManagerImpl.getDestinationF
actory(DestinationFactoryManagerImpl.java:122)
       at
org.apache.cxf.endpoint.ServerImpl.initDestination(ServerImpl.java:79)
       at org.apache.cxf.endpoint.ServerImpl.<init>(ServerImpl.java:63)
       at
org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.j
ava:160)
       ... 23 more

[/console]

... and the relevant piece of configuration for CXF looks like this:

[config]

...

       <import resource="classpath:META-INF/cxf/cxf.xml" />
       <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
       <import resource="classpath:META-INF/cxf/cxf-extension-*.xml" />

...

[/config]

Did anyone try this setup already?

Any help with this would be much appreciated.

Thanks in advance and cheers,

Aleks

Reply via email to