0

我添加了一个 cxf 插件来在所有创建的类上生成 toString()。该方法已添加并编译正常,但是当我将 maven 打包的 jar 添加到另一个项目的构建路径并将对象添加到我的 toString 时,我收到:

java.lang.NoClassDefFoundError: org/apache/cxf/xjc/runtime/JAXBToStringStyle
    at com.resx.services.Profile.toString(Profile.java:420)
    at java.lang.String.valueOf(String.java:2826)
    ...
Caused by: java.lang.ClassNotFoundException: org.apache.cxf.xjc.runtime.JAXBToStringStyle

我假设我的 pom 设置错误,但我不确定。这是 pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <groupId>com.trx</groupId>
  <artifactId>resxWebservices</artifactId>
  <version>10.4.1</version>

  <name>resxWebservices</name>
  <packaging>jar</packaging>

  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-codegen-plugin</artifactId>
        <version>2.6.0</version>
        <executions>
          <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>
              <sourceRoot>src</sourceRoot>
              <wsdlOptions>
                <wsdlOption>
                  <wsdl>./resxWebservices.wsdl</wsdl>
                  <extraargs>
                    <extraarg>-xjc-Xts</extraarg>
                  </extraargs>
                </wsdlOption>
              </wsdlOptions>
            </configuration>
            <goals>
              <goal>wsdl2java</goal>
            </goals>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.apache.cxf.xjc-utils</groupId>
            <artifactId>cxf-xjc-runtime</artifactId>
            <version>2.6.0</version>
          </dependency>
          <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
          </dependency>
          <dependency>
            <groupId>org.apache.cxf.xjcplugins</groupId>
            <artifactId>cxf-xjc-ts</artifactId>
            <version>2.6.0</version>
          </dependency>
        </dependencies>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <verbose>true</verbose>
          <fork>true</fork>
          <executable>${JAVA_HOME}/bin/javac</executable>
          <compilerVersion>1.6</compilerVersion>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>org.apache.cxf.xjc-utils</groupId>
      <artifactId>cxf-xjc-runtime</artifactId>
      <version>2.6.0</version>
    </dependency>
    <dependency>
      <groupId>commons-lang</groupId>
      <artifactId>commons-lang</artifactId>
      <version>2.6</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf.xjcplugins</groupId>
      <artifactId>cxf-xjc-ts</artifactId>
      <version>2.6.0</version>
    </dependency>
  </dependencies>
</project>

我也尝试过添加

<scope>compile</scope>

到具有相同问题的依赖项。

4

1 回答 1

2

当您运行另一个项目时,您还需要确保 cxf jar 在类路径中可用。

您应该将您的第一个项目列为第二个项目的依赖项,以确保传递正确的依赖项(而不是仅将 jar 本身添加到构建路径)

或者,为第一个项目创建一个包含 cxf jar 的 jar-with-dependencies,并将其添加到第二个项目的 duild/runtime 类路径

于 2012-06-06T19:31:24.403 回答