0

I am starting a project to read and analyze a JSON-file with JAVA 8. To have it run in Eclipse, I turned it into a maven project and added this dependency :

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.json</artifactId>
    <version>1.1</version>
    <scope>runtime</scope>
</dependency>

Within Eclipse , there is no problem, but when I run it from command line, I get this error:

Provider org.glassfish.json.JsonProviderImpl not found

In futur I want to run it on a server without an Eclipse installation. How can I get it running ?

AxelR
  • 1
  • Does this answer your question? https://stackoverflow.com/a/47035781/4417924 – Jason Apr 01 '20 at 23:03
  • Does this answer your question? [How can I create an executable JAR with dependencies using Maven?](https://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven) – J Fabian Meier Apr 02 '20 at 04:45

3 Answers3

0

Please see this question. It will help you create a jar file that has all the dependencies built into it. I would not suggest rewriting things and to use libraries freely. You code much faster and in more bug free ways when you do not code it yourself.

Once you have done this you will be able to run java -jar on the jar file and your application will run. If you would like to just have the thing run you can download the jar and add it to the classpath variable that you pass the java command line.

ojblass
  • 21,146
  • 22
  • 83
  • 132
0

thanks a lot. Following maven configuration gets it work for command line :

<plugins>
..    
<plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>single</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
              </descriptorRefs>
              <archive>
                <manifest>
                    <mainClass>data.Parser</mainClass>
                </manifest>
              </archive>
            </configuration>
        </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.json</artifactId>
        <version>1.1</version>
        <scope>runtime</scope>
    </dependency>
  </dependencies>
AxelR
  • 1
-1

if you want simply deserialize using Gson. you use this sample program

import java.io.File;
import java.io.IOException;
import java.util.Map;

import org.apache.commons.io.FileUtils;

import com.google.gson.Gson;

public class Main {

    public static void main(String[] args) throws IOException {

        String json = FileUtils.readFileToString(new File("PATH_TO_JSON"), "UTF-8");
        Gson deserializer = new Gson();
        System.out.println(deserializer.fromJson(json, Map.class));
    }
}

you will need following dependencies

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.6</version>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.5</version>
    </dependency>
user3817206
  • 315
  • 4
  • 14