1

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.

Alatha Ntonga
  • 73
  • 1
  • 11
  • 1
    When you run from Intellij, this works since the IDE includes all necessary jar-s in the classpath. in order to run from the command line using the `java -jar ..` option, one way to go is to create an "uber-jar" to package all necessary binaries; see the SO question https://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven – Daniele Nov 16 '19 at 15:02
  • You should not try to run the sources JAR. There should be a standalone JAR for the examples that will run with java -jar. – Christoph John Nov 16 '19 at 15:26
  • 1
    You would need to include the quickfixj jars to the classpath: `java -classpath `. Where `` 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 `` is the fully qualified class name of your main class (the class that has the main entry to your application). – TT. Nov 16 '19 at 15:37
  • 1
    @Daniele Thanks. I followed your answer and it worked! I thought I knew maven but turns out I was being a noob. :) – Alatha Ntonga Nov 16 '19 at 18:33
  • 1
    @ChristophJohn Thanks I didn't properly look at the pom, otehrwise I would have realised the standalone jar is the one I needed to run. Also I'd Iike to say thank you, I've asked other questions and you've been very helpful. – Alatha Ntonga Nov 16 '19 at 18:36
  • 1
    @TT thanks. Your explanation made it crystal clear . I hope you don't mind, I've used your comment in the answer. – Alatha Ntonga Nov 16 '19 at 18:54

2 Answers2

1

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)

Alatha Ntonga
  • 73
  • 1
  • 11
0

You have to create an executable jar. You can use Maven to do this. In your pom.xml can use maven-assembly-plugin to generate your executable jar

<plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>myour.main.Class</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
        </plugin>
Gus
  • 1
  • 2