1

我正在使用axis2为旧版应用程序重新生成我需要使用的更新的Web服务的客户端代码。

作为一个遗留应用程序,我想避免更改已经编写的代码,并重新生成类,因为它们是由 eclipse 插件在多年前生成的,但这次使用 maven 而不是 eclipse .

所以我看到它们是使用axis2和xmlbeans生成的,我在maven插件中生成了配置:

<plugin>
    <groupId>org.apache.axis2</groupId>
    <artifactId>axis2-wsdl2code-maven-plugin</artifactId>
    <version>1.5.6</version>
    <executions>
        <execution>
            <id>TheirsWs</id>
            <goals>
                <goal>wsdl2code</goal>
            </goals>
            <phase>generate-sources</phase>
            <configuration>
                <packageName>it.theirs.ws</packageName>
                <wsdlFile>${basedir}/src/main/resources/theirWs.wsdl</wsdlFile>
                <generateServerSide>false</generateServerSide>
                <databindingName>xmlbeans</databindingName>
                <unpackClasses>true</unpackClasses>
            </configuration>
        </execution>
    </executions>
</plugin>

现在发生的事情是一件非常好的事情。插件在generate-sources/axis2/wsdl2code/resource文件夹下生成一个.class文件,但是maven没有添加到最终包中,导致调用webservice时出现a。ClassNotFoundException

4

2 回答 2

1

我通过使用包含和排除文件夹的 maven 默认功能将资源文件夹添加到 JAR 中来解决问题。您的案例的解决方案将是:

<build>
<!-- This will the MAVEN to copy the entire folder, you can copy only the .class files -->
<resources>
        <resource>
            <directory>${project.build.directory}/generated-src/resources</directory>
            <includes>
                 <include>**/*</include>
            </includes>     
        </resource>
    </resources>
<plugin>
    <groupId>org.apache.axis2</groupId>
    <artifactId>axis2-wsdl2code-maven-plugin</artifactId>
    <version>1.5.6</version>
    <executions>
        <execution>
            <id>TheirsWs</id>
            <goals>
                <goal>wsdl2code</goal>
            </goals>
            <phase>generate-sources</phase>
            <configuration>
                <packageName>it.theirs.ws</packageName>
                <wsdlFile>${basedir}/src/main/resources/theirWs.wsdl</wsdlFile>
                <generateServerSide>false</generateServerSide>
                <databindingName>xmlbeans</databindingName>
                <!-- I add this line just to be easy to referenciate the souce -->
                <outputDirectory>${project.build.directory}/generated-src</outputDirectory>
                <unpackClasses>true</unpackClasses>
            </configuration>
        </execution>
    </executions>
</plugin>

于 2017-03-30T15:00:13.577 回答
0

Had the same problem, i changed the Ant build.xml buildfile from:

<target depends="pre.compile.test" name="compile.src" if="jars.ok">
    <javac debug="on" memoryMaximumSize="256m" memoryInitialSize="256m" fork="true" destdir="${classes}" srcdir="${src}">
        <classpath refid="axis2.class.path"/>
    </javac>
</target>

To:

<target depends="pre.compile.test" name="compile.src" if="jars.ok">
    <javac debug="on" memoryMaximumSize="256m" memoryInitialSize="256m" fork="true" destdir="${classes}" srcdir="${src}">
        <classpath refid="axis2.class.path"/>
    </javac>
    <copy todir="${classes}">
        <fileset dir="${resources}"/>
    </copy>
</target>

The new Copy task add all the resources to the target classes folder so the generated Jar will include them.

Hope it helps.

于 2016-04-12T11:15:23.483 回答