0

I am trying to run my java program TopicPublisher.java via command line. There are several dependencies specified through Maven.

In the directory with the pom.xml file, I ran the following commands: mvn clean, mvn package, and java -cp target/SOM_Enrichment-1.0-SNAPSHOT.jar TopicPublisher.

I get the following error:

Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.NoClassDefFoundError: om/solacesystems/jcsmp/JCSMPStreamingPublishEventHandler

Below is a screenshot of my directory tree:

directory tree

Any ideas how to solve this?

[EDIT]

Pom File:

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>CAMM</groupId>
<artifactId>SOM_Enrichment</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id> <!-- this is used for inheritance merges -->
                    <phase>package</phase> <!-- bind to the packaging phase -->
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>

</build>

<dependencies>
    <dependency>
        <groupId>com.solacesystems</groupId>
        <artifactId>sol-jcsmp</artifactId>
        <version>[10,)</version>
    </dependency>
</dependencies>

2
  • Pom jdk version and the jdk on your computer? Commented Jul 11, 2018 at 20:22
  • @Alec I didn't specify the pom jdk version; not sure what the default is but I think it's the one I'm currently using which is the jdk on my computer. the version is 1.8. Commented Jul 11, 2018 at 20:41

2 Answers 2

2

Your program loads classes from the com.solacesystems dependency in your pom.xml, but your classpath only contains your build artifact jar. Build a fat jar, as @Kerry suggests, or use the exec-maven-plugin to run from the command line. From within your project directory (where you execute mvn package), execute:

mvn exec:java -Dexec.mainClass=TopicPublisher

The plugin builds the classpath argument from the dependencies defined in your pom. See https://www.mojohaus.org/exec-maven-plugin/ for more options.

Sign up to request clarification or add additional context in comments.

3 Comments

oh wow this works! seems like the issue is that my dependencies are not in the jar but i tried Kerry's suggestion to no avail.. :-/
This runs the application but does it build a JAR with third party dependencies?
i don't think it does @Kerry. i appreciate your help but i think i have to give Kerry the answer. thanks so much though :)
2

Without seeing your full POM.xml I am assuming you have not build the final artifact to be a 'fat jar'. By this I mean that the JAR not only contains your own classes but all the third party dependencies.

You would need to use something like the Maven assembly plugin or the Maven shade pluginto do this for you. From the screenshot though I see you are using IntelliJ so you should also be able to run through your IDE obviously for just testing purposes.

2 Comments

thanks for your answer. i followed the instructions and updated my pom.xml file. the error still persists though..
I seem to remember I needed to use the shade plugin. Have you tried that instead of the assembly plugin?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.