当前位置: 首页 > 面试题库 >

使用Maven包括JAXB

洪鸿
2023-03-14
问题内容

在1.6.0_16 JDK上工作时,我使用Apache CXF 2.5.2从WSDL生成了存根类,Apache CXF 2.5.2使用了最新的jaxb-
api 2.2。我知道可以使用jaxb-api 2.1,但是为了避免兼容性问题,我宁愿使用当前版本。由于我的JDK具有jaxb
2.1,因此构建失败并显示以下消息:

error at @XmlElementRef(name = "protocol", namespace = "urn:ch.beo.emc", type = JAXBElement.class, required = false)

因此,我尝试使用以下依赖项使Maven包括最新的jaxb api和impl。

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.2.5</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.2.5</version>
</dependency>

虽然这两个jar已添加到Eclipse中的Maven依赖关系中,但错误消息在Eclipse和Maven构建中均持续存在。

如何在我的Maven构建中包括这些jar,并在Eclipse和目标系统上使用它们?

PS:请在此处找到完整的POM:

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>ch.beo</groupId>
    <artifactId>emc.front</artifactId>
    <version>3.1.3-SNAPSHOT</version>
    <repositories>
        <repository>
            <id>jboss</id>
            <name>JBoss</name>
            <url>http://repository.jboss.org/maven2/</url>
        </repository>
        <repository>
            <id>freehep</id>
            <name>Freehep</name>
            <url>http://java.freehep.org/maven2</url>
        </repository>
        <repository>
            <id>JCurl</id>
            <url>http://jcurl.berlios.de/m2/repo</url>
        </repository>
        <repository>
            <id>JavaNet</id>
            <url>http://download.java.net/maven/2/</url>
        </repository>
        <repository>
            <id>djmaven2</id>
            <url>http://www.fdvs.com.ar/djmaven2</url>
            <name>DynamicJasper public Repository</name>
        </repository>
    </repositories>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <build>
        <defaultGoal>compile</defaultGoal>
        <sourceDirectory>src/main/java</sourceDirectory>
        <testSourceDirectory>src/test/java</testSourceDirectory>
        <outputDirectory>target/main</outputDirectory>
        <testOutputDirectory>target/test</testOutputDirectory>
        <resources>
            <resource>
                <targetPath>ch/beo/emc/front/resources</targetPath>
                <directory>src/main/resources</directory>
                <excludes>
                    <exclude>src/main/resources/security/jarsign</exclude>
                </excludes>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <targetPath>ch/beo/emc/front/resources</targetPath>
                <directory>src/test/resources</directory>
            </testResource>
            <testResource>
                <targetPath>ch/beo/emc/front/resources</targetPath>
                <directory>src/main/resources</directory>
                <excludes>
                    <exclude>src/main/resources/security/jarsign</exclude>
                </excludes>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.1</version>
                <configuration>
                    <complianceLevel>1.6</complianceLevel>
                    <aspectLibraries>
                        <aspectLibrary>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-aspects</artifactId>
                        </aspectLibrary>
                    </aspectLibraries>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>ch.beo.emc.front.factory.Front</mainClass>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib</classpathPrefix>
                        </manifest>
                    </archive>
                    <descriptors>
                        <descriptor>assembly.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <includes>
                        <include>ch/beo/emc/front/AllTests.java</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>ch.beo.emc.front.factory.Front</mainClass>
                                </transformer>
                                <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>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <executions>
                    <execution>
                        <id>sign</id>
                        <phase>package</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                        <configuration>
                            <keystore>src/main/resources/security/jarsign/server.pfx</keystore>
                            <type>pkcs12</type>
                            <alias>beo-it.ch</alias>
                            <storepass>****</storepass>
                            <signedjar>${project.build.directory}/signed/${project.build.finalName}.jar</signedjar>
                            <verify>true</verify>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>com.l2fprod</groupId>
            <artifactId>l2fprod-common-all</artifactId>
            <version>6.9.1</version>
        </dependency>
        <dependency>
            <groupId>org.swixml</groupId>
            <artifactId>swixml</artifactId>
            <version>1.5.144</version>
        </dependency>
        <dependency>
            <groupId>net.java.balloontip</groupId>
            <artifactId>balloontip</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>org.swinglabs</groupId>
            <artifactId>swingx</artifactId>
            <version>1.6</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>2.5.6.SEC01</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>2.5.6.SEC01</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>2.5.6.SEC01</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>2.5.6.SEC01</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>2.5.6.SEC01</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>2.5.6.SEC01</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <artifactId>junit</artifactId>
                    <groupId>junit</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>jfree</groupId>
            <artifactId>jfreechart</artifactId>
            <version>1.0.9</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.4</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.java.jnlp</groupId>
            <artifactId>jnlp</artifactId>
            <version>6.0</version>
        </dependency>
        <dependency>
            <groupId>com.thoughtworks.xstream</groupId>
            <artifactId>xstream</artifactId>
            <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.5</version>
        </dependency>
        <dependency>
            <groupId>org.jscience</groupId>
            <artifactId>jsr-275</artifactId>
            <version>0.8.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.7</version>
        </dependency>
        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports</artifactId>
            <version>3.7.4</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-beanutils</groupId>
                    <artifactId>commons-beanutils</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>commons-collections</groupId>
                    <artifactId>commons-collections</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>jfree</groupId>
                    <artifactId>jcommon</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>jfree</groupId>
                    <artifactId>jfreechart</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>xml-apis</groupId>
                    <artifactId>xml-apis</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>bouncycastle</groupId>
                    <artifactId>bcmail-jdk14</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>bouncycastle</groupId>
                    <artifactId>bcprov-jdk14</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>bouncycastle</groupId>
                    <artifactId>bctsp-jdk14</artifactId>
                </exclusion>
                <exclusion>
                    <artifactId>jdtcore</artifactId>
                    <groupId>eclipse</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jdt.core.compiler</groupId>
            <artifactId>ecj</artifactId>
            <version>3.5.1</version>
        </dependency>
        <dependency>
            <groupId>ar.com.fdvs</groupId>
            <artifactId>DynamicJasper</artifactId>
            <version>3.1.2</version>
            <exclusions>
                <exclusion>
                    <groupId>jasperreports</groupId>
                    <artifactId>jasperreports</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.2.5</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.2.5</version>
        </dependency>
    </dependencies>
</project>

问题答案:

我也刚与jaxb碰到这个问题;天哪,我爱Maven(不是)。这是我解决问题的方法。

添加中央仓库

<存储库>
    <id>中央</ id>
    <url> http://repo.maven.apache.org/maven2/ </ url>
</ repository>

修改api和impl的版本

<依赖性>
    <groupId> javax.xml.bind </ groupId>
    <artifactId> jaxb-api </ artifactId>
    <version> 2.2.7-SNAPSHOT </ version>
</ dependency>
<依赖性>
    <groupId> com.sun.xml.bind </ groupId>
    <artifactId> jaxb-impl </ artifactId>
    <version> 2.2.5-b10 </ version>
</ dependency>


 类似资料:
  • 问题内容: 默认情况下,在构建过程中,maven会删除空目录。 您是否知道可以在pom中指定一个参数来指示maven在生成的target / test-classes文件夹中包括空目录? 问题答案: 根据票证MRESOURCES-36,应该有一个元素,但仅适用于 Maven Resources Plugin 2.3 。 对于包含旧版资源插件的Maven版本: 在此问题解决之前,这是我一直在成功使用

  • 问题内容: 如何创建将使项目可构建的maven pom,我可以直接在我的项目中包含专有的jar,而不必将它们从存储库中取出吗?有人做过吗? 编辑: 我不想通过使用依赖项jar构建程序集来使其可运行,我希望它是可构建的。因此,拥有此项目的任何人都可以构建它,即使在任何存储库中都找不到jars。 问题答案: 1 您可以在应用程序的类路径中包含该jar 2 ,可以通过以下方式在您的maven reopo

  • 我有一个配置了maven-surefire插件的根pom和一个配置了gwt-maven-plugin的gwt模块pom。升级到Maven 3后,我遇到了奇怪的错误。 该项目类似于此处描述的配置:将GwtTest测试与标准单元测试分开 和 它适用于maven 2,但与maven 3我得到: gwt插件似乎无法解析surefire插件的层次结构样式。 只有当我将gwt插件中的所有排除/包括设置为一个逗

  • 问题内容: 我正在尝试用Spring 3.0(和Maven)做我的第一个项目。我已经在许多项目中使用Spring 2.5(和入门版本)。尽管如此,我还是有些困惑,我必须在pom.xml中将哪些模块定义为依赖项。我只想使用核心容器功能(bean,核心,上下文,el)。 我曾经这样做: 但是现在我有点困惑,因为不再有用于3.0版的完整包装的spring模块。我尝试了以下操作,但是没有用(缺少某些类)。

  • 我是IntelliJ和Gradle的新手,我有一个Maven项目,有很多依赖项,它自己工作。现在我应该使用该项目中的库,并在Gradle中为IntelliJ创建一个插件。 我尝试了各种方法在IntelliJ模块设置中添加依赖项,这允许我使用所需的类来编写代码并构建代码。然而,当我试图启动插件时,它再也找不到类了。我想我需要在构建中详细说明这些。但我不明白到底是如何做到的,因为我尝试的所有方法都不起