简体   繁体   English

如何执行 Quickfix/J jar?

[英]how to execute Quickfix/J jar?

I'm building a self contained trading simulator using the quickfix/j library.我正在使用 quickfix/j 库构建一个独立的交易模拟器。 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.到目前为止,我一直在使用 mvn package,然后是 intelli J“运行按钮”从我的客户端应用程序 class 中的入口点运行我的程序。 I tried using the java -jar target/.....1.1.0.jar .我尝试使用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.我认为该错误可能与我的 pom 文件没有正确获取依赖项有关。 So to make sure I ran the ordermatch example from the quickfix/J github, but i get a similar error.因此,为了确保我从 quickfix/J github 运行了ordermatch示例,但我得到了类似的错误。

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.为了清楚起见,使用主类中的 Intellli J“运行”按钮即使对于 ordermacth 示例也可以完美地工作。 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从我收集到的 IntelliJ 使用的命令"/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.如果这有帮助,我可以包含我的 pom 文件和其他信息。 I'm also using a multi-module maven project but that doesn't seem to the problem.我也在使用多模块 maven 项目,但这似乎不是问题。

Turns out I was beeing a noob.原来我是个菜鸟。 The Maven package lifecycle bundles the specified class files without the dependencies into a jar. Maven package 生命周期将没有依赖关系的指定 class 文件捆绑到 Z68995FCBF432492DAC45048DZ49中。 I needed to create an uber jar with all the necessary bianries, and then run that.我需要用所有必要的二进制文件创建一个超级 jar,然后运行它。 See the SO question create excecutable jar with dependencies using maven请参阅 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; <list-of-all-jars>是一个; (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) (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 具有您的应用程序的主要入口)

You have to create an executable jar.您必须创建一个可执行文件 jar。 You can use Maven to do this.您可以使用 Maven 来执行此操作。 In your pom.xml can use maven-assembly-plugin to generate your executable jar在你的 pom.xml 可以使用 maven-assembly-plugin 来生成你的可执行文件 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM