Apache CXF client loads fine in Eclipse but standalone jar throws NullpointerException in WSDLServiceFactory

后端 未结 4 625
旧巷少年郎
旧巷少年郎 2020-12-09 10:11

My goal is to create a Web Service client that runs in a standalone jar with all the dependencies using mvn assembly:single

I generated the client using CXF codegen

相关标签:
4条回答
  • 2020-12-09 10:16

    In complement to @Matt R's answer, I replaced the POM part with the maven-assembly-plugin with this code:

    <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>com.xxx.App</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <!--  transformers for CXF (see http://stackoverflow.com/a/9069435/61298) -->
                                <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/services/com.sun.tools.xjc.Plugin</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/spring.schemas</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/cxf/cxf.extension</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
                                    <resource>META-INF/extensions.xml</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
                                    <resource>META-INF/cxf/extensions.xml</resource>
                                </transformer>
                                <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.XmlAppendingTransformer">
                                    <resource>META-INF/cxf/bus-extensions.xml</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
                                    <resource>META-INF/wsdl.plugin.xml</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
                                    <resource>META-INF/tools.service.validator.xml</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
                                    <resource>META-INF/cxf/java2wsbeans.xml</resource>
                                </transformer>
                            </transformers>
                            <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>
    

    The exclude part is to prevent from having Java Security issues.

    0 讨论(0)
  • 2020-12-09 10:28

    Most likely it's how you are creating your single jar. A normal usage of the assembly plugin would not allow that as various parts of CXFs META-INF/* stuff would need to be merged together. That would include all the /META-INF/spring* and much of the stuff in /META-INF/cxf/* I would suggest using the shade plugin for that. See the pom.xml for CXF's bundle jar for an example.

    http://svn.apache.org/repos/asf/cxf/trunk/osgi/bundle/all/

    0 讨论(0)
  • 2020-12-09 10:30

    Expanding on @DanielKulp's answer, which worked a treat for me with CXF 2.7.7 (just in case the link dies). Configure your shade plugin with the following additional transformers:

    <configuration>
      <transformers>
        <!--  transformers for CXF (see http://stackoverflow.com/a/9069435/61298) -->
        <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/services/com.sun.tools.xjc.Plugin</resource>
        </transformer>
        <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
          <resource>META-INF/spring.schemas</resource>
        </transformer>
        <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
          <resource>META-INF/cxf/cxf.extension</resource>
        </transformer>
        <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
          <resource>META-INF/extensions.xml</resource>
        </transformer>
        <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
          <resource>META-INF/cxf/extensions.xml</resource>
        </transformer>
        <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.XmlAppendingTransformer">
          <resource>META-INF/cxf/bus-extensions.xml</resource>
        </transformer>
        <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
          <resource>META-INF/wsdl.plugin.xml</resource>
        </transformer>
        <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
          <resource>META-INF/tools.service.validator.xml</resource>
        </transformer>
        <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
          <resource>META-INF/cxf/java2wsbeans.xml</resource>
        </transformer>
      </transformers>
    </configuration>
    
    0 讨论(0)
  • 2020-12-09 10:34

    You should try with the one jar plugin, it let's you create super jars that are clean and totaly self-contained

    http://code.google.com/p/onejar-maven-plugin/

    0 讨论(0)
提交回复
热议问题