我正在使用quickfix/j库构建一个独立的交易模拟器。直到现在,我一直在使用mvn包,然后智能J“运行按钮”从我的客户机应用程序类的入口点运行我的程序。我试过使用java -jar target/.....1.1.0.jar。并得到以下错误
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我认为这个错误可能与我的pom文件没有正确获取依赖有关。因此,为了确保我从quickfix/J运行了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为了清楚地使用Intellli "Run“按钮,即使在ordermacth示例中,主calss中的按钮也能很好地工作。据我所知,IntelliJ使用的命令类似于这个"/path/to/java/" "-javagent/.../.jar" "/pathtolocalmavenrepo/quickfix-core.jar "/pathtolocalmavenrepo/anotherquickfixdependecy.jar" ....."more quickfix dependency jar files" packagestructure.Main
我不明白为什么这会工作,但我的执行不能。我可以包括我的pom文件和其他信息,如果这会有帮助。我还使用了一个多模块maven项目,但这似乎并不是问题所在。
发布于 2019-11-16 18:51:54
结果发现我是个菜鸟。Maven包生命周期将没有依赖项的指定类文件捆绑到jar中。我需要创建一个包含所有必需的bianries的uber jar,然后运行它。见SO问题使用maven创建带有依赖项的可扩展jar
所需要的是:
java -classpath <list-of-all-jars> <main-class>其中<list-of-all-jars>是;(Windows)或:(*nix)运行程序所需的所有jar的分隔列表(quickfixj、您自己的jar和所需的任何jar),而<main-class>是主类的完全限定类名(具有应用程序主条目的类)。
发布于 2022-09-21 19:43:21
您必须创建一个可执行的jar。你可以用Maven来做这个。在您的pom.xml中,可以使用maven-程序集插件生成可执行的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>https://stackoverflow.com/questions/58891596
复制相似问题