[英]How to run a compiled java project
I am new to maven. 我是maven的新手。 In order to compile my project I hit mvn compile. 为了编译我的项目,我点击了mvn编译。 However I can't figure out how I can run my project from inside the maven. 但是我无法弄清楚如何从maven内部运行我的项目。 For instance when I hit 比如我打的时候
mvn exec:java -Dexec.mainClass="main.java.org.dbalancer.StartProgram" mvn exec:java -Dexec.mainClass =“main.java.org.dbalancer.StartProgram”
maven complaints: maven投诉:
java.lang.NoClassDefFoundError: com/sanityinc/jargs/CmdLineParser$OptionException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
at java.lang.Class.getMethod0(Class.java:2685)
at java.lang.Class.getMethod(Class.java:1620)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:285)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ClassNotFoundException: com.sanityinc.jargs.CmdLineParser$OptionException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 6 more
which means that jargs library is not included in classpath. 这意味着jargs库不包含在类路径中。 However in my project there aren't any libraries included under target folder which means any library I use I should download it on my own and included in classpath (or use .m2/ folder). 但是在我的项目中,目标文件夹下没有任何库,这意味着我使用的任何库我应该自己下载并包含在类路径中(或使用.m2 /文件夹)。 For instance, when I am under target/classes folder, and I have downloaded all the necessary libraries this command works: java -cp .:../../lib/jargs-2.0-SNAPSHOT.jar:../../../dom4j-2.0.0-ALPHA-2.jar:../../../log4j-1.2.17.jar main.java.org.dbalancer.StartProgram 例如,当我在target / classes文件夹下,并且我已经下载了所有必需的库时,这个命令可以工作:java -cp。:../../ lib / jargs-2.0-SNAPSHOT.jar:../ .. /../dom4j-2.0.0-ALPHA-2.jar:../../../log4j-1.2.17.jar main.java.org.dbalancer.StartProgram
However isn't that a little verbose? 然而,这不是一点点冗长吗? How can I run that from inside maven? 我怎么能从maven里面运行它? Can I run it using java command but not downloading on my own the necessary libraries ? 我可以使用java命令运行它,但不能自己下载必要的库吗?
Update : Ok the problem was a library that I included in that way: 更新 :好的问题是我以这种方式包含的库:
<dependency>
<groupId>jargs_local</groupId>
<artifactId>jargs</artifactId>
<version>2.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${basedir}/lib/jargs-2.0-SNAPSHOT.jar</systemPath>
</dependency>
Now jargs where moved to official maven repo. 现在jargs移动到官方maven回购。 However does anyone know how can I speed up mvn exec? 但是有谁知道如何加速mvn exec? It's a bit slow if you just want to check something.. 如果你只是想检查一下,它有点慢..
The maven-exec plugin should set up the classpath for you. maven-exec插件应该为您设置类路径。 Are you perhaps missing jargs as dependency in your pom.xml
(can we see that as well as the complete mvn dump?) 你是否可能在你的pom.xml
缺少jargs作为依赖(我们可以看到它和完整的mvn转储吗?)
Cheers, 干杯,
One simple way to build a self-sufficent runnable jar is to build a jar-with-dependencies with the maven assembly plugin. 构建一个自给自足的runnable jar的一个简单方法是使用maven程序集插件构建一个带有依赖关系的jar。
http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html
you should dependency them int the pom.xml for example: 你应该将它们依赖于pom.xml,例如:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.0</version>
</dependency>
or 要么
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
<compilerArguments>
<extdirs>src\main\webapp\WEB-INF\lib</extdirs>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</build>
or 要么
<dependency>
<groupId>org.swinglabs</groupId>
<artifactId>swingx</artifactId>
<version>0.9.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/swingx-0.9.3.jar</systemPath>
</dependency>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.