Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在启动jar(maven编译)时出错,但在Intellij上简单运行可以正常工作_Java_Json_Maven_Intellij Idea_Jersey - Fatal编程技术网

Java 在启动jar(maven编译)时出错,但在Intellij上简单运行可以正常工作

Java 在启动jar(maven编译)时出错,但在Intellij上简单运行可以正常工作,java,json,maven,intellij-idea,jersey,Java,Json,Maven,Intellij Idea,Jersey,Intellij上的项目运行良好,pom中定义了com.sun.jersey服务器、core和json的依赖项。 然后我创建了jar(为此,我必须将META-INF/MANIFEST.MF从/src/main/java移动到/src/main/resources),看起来还可以(在嵌入jar的文件夹中,我可以在maven下找到所有正确的依赖项)。 然后我启动罐子,它就正确启动了。。。但是,在运行时,当程序尝试从rest api获取json时,会出现以下错误: May 10, 2018 9:33:

Intellij上的项目运行良好,pom中定义了com.sun.jersey服务器、core和json的依赖项。 然后我创建了jar(为此,我必须将META-INF/MANIFEST.MF从/src/main/java移动到/src/main/resources),看起来还可以(在嵌入jar的文件夹中,我可以在maven下找到所有正确的依赖项)。 然后我启动罐子,它就正确启动了。。。但是,在运行时,当程序尝试从rest api获取json时,会出现以下错误:

May 10, 2018 9:33:25 AM com.sun.jersey.api.client.ClientResponse getEntity
GRAVE: A message body reader for Java class java.lang.String, and Java type class java.lang.String, and MIME media type application/json was not found
May 10, 2018 9:33:25 AM com.sun.jersey.api.client.ClientResponse getEntity
GRAVE: The registered message body readers compatible with the MIME media type are:
application/json ->
  com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$App
  com.sun.jersey.json.impl.provider.entity.JSONArrayProvider$App
  com.sun.jersey.json.impl.provider.entity.JSONObjectProvider$App
  com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$App
  com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$App
*/* ->
  com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$General
  com.sun.jersey.json.impl.provider.entity.JSONArrayProvider$General
  com.sun.jersey.json.impl.provider.entity.JSONObjectProvider$General
  com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$General
  com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$General
  com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy

com.sun.jersey.api.client.ClientHandlerException: A message body reader for Java class java.lang.String, and Java type class java.lang.String, and MIME media type application/json was not found
        at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:630)
        at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:586)
        at com.dataCollection.executor.Downloader.download(Downloader.java:49)
        at com.dataCollection.executor.Downloader.run(Downloader.java:34)
        at java.util.TimerThread.mainLoop(Unknown Source)
        at java.util.TimerThread.run(Unknown Source)
由于某些原因,它找不到媒体类型application/json。但是当我从Intellij启动主类时,它工作得很好

下面是程序调用远程服务的一段代码:

Client client = Client.create();
WebResource webResource = client.resource("https://...(correct address)...");
ClientResponse response = webResource.accept("application/json").get(ClientResponse.class);
String output = response.getEntity(String.class);
JSONObject jsonObject = new JSONObject(output);
以下是pom:

<groupId>groupId</groupId>
<artifactId>CollectDataFromREST</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.1.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <minimizeJar>true</minimizeJar>
                        <createDependencyReducedPom>true</createDependencyReducedPom>
                        <dependencyReducedPomLocation>
                            ${java.io.tmpdir}/dependency-reduced-pom.xml
                        </dependencyReducedPomLocation>
                        <relocations>
                            <relocation>
                                <pattern>com.acme.coyote</pattern>
                                <shadedPattern>hidden.coyote</shadedPattern>
                            </relocation>
                        </relocations>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>com.dataCollection.StartDataCollection</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>1.19.4</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-core</artifactId>
        <version>1.19.4</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>1.19.4</version>
    </dependency>
</dependencies>
groupId
从REST收集数据
1.0-快照
org.apache.maven.plugins
maven编译器插件
1.8
1.8
org.apache.maven.plugins
maven阴影插件
3.1.1
包裹
阴凉处
真的
真的
${java.io.tmpdir}/dependency-reduced-pom.xml
土狼
隐藏的狼
com.dataCollection.StartDataCollection
泽西岛
泽西岛客户
1.19.4
泽西岛
球衣核心
1.19.4
泽西岛
泽西json
1.19.4

您可以显示pom.xml文件吗?完成后,pom现在在post中,这就是整个pom?您没有使用任何其他插件(如assembly插件)来创建胖罐子吗?我在pom中添加了maven shade插件,但结果完全相同