Issue
I'm building a self contained trading simulator using the quickfix/j library. Up untill now I'd been using mvn package, then the intelli J "Run button" to run my program from an entry point within my client-application class. I tried using the java -jar target/.....1.1.0.jar
. and get the following error
java -jar Broker/target/Broker-1.0.0.jar
Error: Could not find or load main class Broker.ClientApplication
Caused by: java.lang.NoClassDefFoundError: quickfix/Application
I thought the error might have something to do with my pom file not fetching a dependecy properly. So to make sure I ran the ordermatch example from the quickfix/J github, but i get a similar error.
java -jar /homes/antonga/IdeaProjects/Desktop/quickfixj-parent/quickfixj-examples/ordermatch/target/quickfixj-examples-ordermatch-2.1.1-sources.jar
no main manifest attribute, in /homes/antonga/IdeaProjects/Desktop/quickfixj-parent/quickfixj-examples/ordermatch/target/quickfixj-examples-ordermatch-2.1.1-sources.jar
To be clear using the Intellli J "Run" button inside the main calss works percfectly even for the ordermacth example. From what I gather the command IntelliJ uses is something like this
"/path/to/java/" "-javagent/.../.jar" "/pathtolocalmavenrepo/quickfix-core.jar "/pathtolocalmavenrepo/anotherquickfixdependecy.jar" ....."more quickfix dependency jar files" packagestructure.Main
I don't see why this would work but my execution wouldn't. I can include my pom files and other info if this would help. I'm also using a multi-module maven project but that doesn't seem to the problem.
Solution
Turns out I was beeing a noob. The Maven package lifecycle bundles the specified class files without the dependencies into a jar. I needed to create an uber jar with all the necessary bianries, and then run that. See the SO question create excecutable jar with dependencies using maven
What is required is the following:
java -classpath <list-of-all-jars> <main-class>
Where <list-of-all-jars>
is a ; (Windows) or : (*nix) separated list of all jars needed to run your program (quickfixj jars, your own jar and any jars needed), and <main-class>
is the fully qualified class name of your main class (the class that has the main entry to your application)
Answered By - Alatha Ntonga
Answer Checked By - Katrina (JavaFixing Volunteer)