0

I want to run my working Java project through my terminal (mac). It uses Maven to pull in required dependencies. Any help would be very much appreciated.

First I ran the commend: mvn clean install

Next: mvn dependency:copy-dependencies

Finally: cd target/ java -cp MyProject-1.0-SNAPSHOT.jar:dependency Main

Unfortunately the following error is thrown (clearly showing the dependencies are not being used correctly):

Exception in thread "main" java.lang.NoClassDefFoundError: org/json/simple/parser/JSONParser at Main$Quote.quoteMachine(Hi.java:21) at Main.main(Hi.java:12) Caused by: java.lang.ClassNotFoundException: org.json.simple.parser.JSONParser ...

Biscuit
  • 53
  • 12

2 Answers2

1

I managed to solve the problem by adding this to my POM file:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <configuration>
                <mainClass>main</mainClass>
            </configuration>
        </plugin>
    </plugins>
</build>

After this I simply ran the following commands in my terminal:

mvn clean install

And then:

mvn exec:java
Biscuit
  • 53
  • 12
  • Yes, that's the way to go. Otherwise, see this answer: https://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven#574650 – Moritz Petersen Feb 12 '19 at 15:49
0

you need to include the json-simple-.jar in your classpath.

Sai prateek
  • 11,842
  • 9
  • 51
  • 66