10

Three weeks ago I had finished work on a web application. Everything was running without problems.

Now, three weeks later, having changed nothing(!!!), I wanted to run the application again but this time I got the following error message:

 An error occurred while parsing the server response. Error message is: Provider org.glassfish.json.JsonProviderImpl not found
Exception in thread "main" com.michael.optimizer.exceptions.JsonException: This is a general JSON error. Check logs for details.)
    at com.michael.optimizer.api.JsonRequest.doJsonRequest(JsonRequest.java:36)
    at com.michael.optimizer.api.StationApi.doJsonRequest(StationApi.java:150)
    at com.michael.optimizer.api.StationApi.areaSearch(StationApi.java:73)
    at com.michael.optimizer.Optimizer.main(Optimizer.java:23)
Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
    at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:404)
    at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:166)
    at org.codehaus.mojo.exec.ExecMojo.executeCommandLine(ExecMojo.java:764)
    at org.codehaus.mojo.exec.ExecMojo.executeCommandLine(ExecMojo.java:711)
    at org.codehaus.mojo.exec.ExecMojo.execute(ExecMojo.java:289)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 5.823 s
Finished at: 2020-04-23T20:20:56+02:00
Final Memory: 7M/123M
------------------------------------------------------------------------
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.5.0:exec (default-cli) on project optimizer: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

What's wrong here?


The content of my pom.xml file is the following:

<?xml version="1.0" encoding="UTF-8"?>
<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.michael</groupId>
    <artifactId>optimizer</artifactId>
    <version>1.0-SNAPSHOT</version>


    <name>optimizer</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>7.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongo-java-driver</artifactId>
            <version>3.4.1</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <type>jar</type>
        </dependency>
    </dependencies>
</project>
steady_progress
  • 3,311
  • 10
  • 31
  • 62
  • So, were you trying to deploy to Glassfish? What command are you running exactly? Have you reinstalled the server? – acm Apr 24 '20 at 12:50
  • 1
    I'm using the payara server, not the glassfish server. But these two seem to be closely related. – steady_progress Apr 25 '20 at 20:53
  • 3
    Have you checked that org.glassfish:javax.json dependency is present? See https://stackoverflow.com/questions/47022653/provider-org-glassfish-json-jsonproviderimpl-not-found-at-javax-json-spi-jsonpro/47035781 and https://stackoverflow.com/questions/33083050/provider-org-glassfish-json-jsonproviderimpl-not-found where in both cases the missing dependency was the problem... – blagerweij Apr 25 '20 at 22:48
  • 1
    The json dependency should be provided by the application server. See for example: https://stackoverflow.com/questions/57726562/maven-dependencies-provided-by-wildfly-17-server – assylias Apr 27 '20 at 09:57
  • Upgrade your maven version to the latest - 3.6.3 and rebuild – Ashish Patel Apr 30 '20 at 18:16

3 Answers3

3

I took dependencies from your pom.xml for testing.

I created my 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.michael</groupId>
    <artifactId>optimizer</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongo-java-driver</artifactId>
            <version>3.4.1</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
        </dependency>
    </dependencies>
</project>

I checked whether it contains the necessary jars for this issue.

I used maven command : mvn dependency:tree. Using this command, you can see which jars and dependent jars are used.

enter image description here

These -> javax.json & javax.json-api artifacts are missing.

Add this dependency in pom.xml to ignore this error :

<!-- This jar provides the interfaces -->
<!-- This may be optional as javaee-web-api contains JsonProvider.class -->
<!-- But still I will recommend to add this explicitly for you to be at safer side -->
<dependency>
    <groupId>javax.json</groupId>
    <artifactId>javax.json-api</artifactId>
    <version>1.0</version> 
</dependency> 
<!-- This jar provides the implementation of this interfaces
<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.json</artifactId>
    <version>1.1.4</version>
</dependency>

Note :javax.json-api implementation is done by javax.json.

Anish B.
  • 9,111
  • 3
  • 21
  • 41
3

You are using javaee-web-api dependency and it has javax.json.spi.JsonProvider.class class file not the actual implementation.

You need to have the actual implementation of the JsonProvider. So add javax.json dependency. It has JsonProvider implementation class org.glassfish.json.JsonProviderImpl.class .

<!-- https://mvnrepository.com/artifact/org.glassfish/javax.json -->
<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.json</artifactId>
    <version>1.1.4</version>
</dependency>

For more details, check here.

Vikas
  • 6,868
  • 4
  • 27
  • 41
2

@Anish B.: javax.json dependency has the JsonProvider implementation class as dependency (as pointed out by Code_Mode) ... but (as pointed out by assylias), in fact not even the javax.json dependency is needed as the application server should provide this dependency.

Michael
  • 799
  • 1
  • 7
  • 16
  • in fact I have a problem with the server (see https://stackoverflow.com/questions/61445520/getting-error-message-failed-to-load-resource-the-server-responded-with-a-stat?noredirect=1#comment108697919_61445520) ... it makes sense that everything should be provided by the server because when the server was running smoothly (3 weeks ago), I didn't need to put those dependencies into the pom.xml file .... things worked without that ... which means they must have been provided by the application server – steady_progress Apr 27 '20 at 18:17
  • @Code_Mode: It seems that the pom.xml file doesn't need to be augmented at all ... the problem is apparently that the server is not working as it should ... so the solution to this question: https://stackoverflow.com/questions/61445520/getting-error-message-failed-to-load-resource-the-server-responded-with-a-stat?noredirect=1#comment108697919_61445520 will also be the answer to the question posted here. ... so whoever finds a solution for that other question will be awarded the 500 point bounty – steady_progress Apr 27 '20 at 18:22
  • 1
    @Anish B.: It seems that the pom.xml file doesn't need to be augmented at all ... the problem is apparently that the server is not working as it should ... so the solution to this question: https://stackoverflow.com/questions/61445520/getting-error-message-failed-to-load-resource-the-server-responded-with-a-stat?noredirect=1#comment108697919_61445520 will also be the answer to the question posted here. ... so whoever finds a solution for that other question will be awarded the 500 point bounty – steady_progress Apr 27 '20 at 18:24
  • @steady_progress Ok !! Can you share your code base for testing ? I will download payara application server by myself. – Anish B. Apr 27 '20 at 19:19
  • @steady_progress Please also add the payara server version as well ? I will try to solve the problem. – Anish B. Apr 27 '20 at 19:21
  • @Michael Thanks for pointing out. I was thinking the same at the beginning. Later on, I thought for this solution. – Anish B. Apr 27 '20 at 19:23