0
votes

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?cela
@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.Shi Zhang

2 Answers

2
votes

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
votes

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.