Maven + Resteasy JAXB找不到内容类型application/xml的编写器 [英] Maven + Resteasy JAXB could not find writer for content-type application/xml

查看:61
本文介绍了Maven + Resteasy JAXB找不到内容类型application/xml的编写器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个供其他项目使用的.jar,其中包括ReastEasy库(jaxb,jaxrs,jaxrs-clients等).

I want to create a .jar that will be used in other projects which amongst others, makes use of the ReastEasy libraries (jaxb, jaxrs, jaxrs-clients etc).

尽管我包括了所有库,并且在基于Maven的项目中一切正常,但是显然.jar中没有包含某些库,而在简单的Java SE项目中,.jar仅包含在.jar中,我遇到了以下异常: lib文件夹:

Although I am including all libraries, and everything works well in maven based projects, apparently some libraries are not included in the .jar and I am getting the following exception in simple Java SE projects where the .jar is just included in the lib folder:

RuntimeException: could not find writer for content-type application/xml type

.jar由Maven和程序集插件mvn clean compile assembly:single

The .jar is build with Maven and the assembly plugin mvn clean compile assembly:single

以下是我的pom.xml

<dependencies>

    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>1.0.1.Final</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.2.0.Final</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>5.0.3.Final</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxrs</artifactId>
        <version>2.3.6.Final</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxb-provider</artifactId>
        <version>2.3.6.Final</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jackson-provider</artifactId>
        <version>2.3.6.Final</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>jaxrs-api</artifactId>
        <version>2.3.6.Final</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.6</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.6</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.2</version>
        <scope>compile</scope>
    </dependency>

</dependencies>

<build>

    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.2</version>
        </plugin>

        <plugin>

            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <appendAssemblyId>false</appendAssemblyId>
            </configuration>
        </plugin>
    </plugins>
</build>

推荐答案

我通过使用Maven阴影构建它来解决了这个问题.

I solved this problem by building it with maven shade.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>com.google.MainClass</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

这里最重要的一行是这样:

The most important line here is this:

<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />

阴影插件配置需要服务转换器合并服务使用的META-INF/services文件发现机制.

The shade plugin configuration needs the service transformer which merges the META-INF/services files used by the service discovery mechanism.

这篇关于Maven + Resteasy JAXB找不到内容类型application/xml的编写器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆