我正在尝试在命令行上使用Maven运行Java程序,但它没有将正确的条目放入类路径中。如果我在具有Maven支持的IntelliJ中运行程序,则类路径包括80个左右的条目,包括我的项目的jar依赖项、编译程序类以及来自src/main/resources的资源。如果我使用
Maven版本:
mvn exec:java
运行程序,我只得到一个条目apache-maven-3.0.4/boot/plexus-classworlds-2.4.jar
,在整个项目树中没有对plexus
的引用。这个条目是从哪里来的?为什么其他预期的类路径条目不在那里?Maven版本:
Apache Maven 3.0.4 (r1232337; 2012-01-17 00:44:56-0800)
pom.xml:<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>MyProject</artifactId>
<version>SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- lots of dependencies -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<executable>${env.JAVA_HOME}/bin/javac</executable>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>${basedir}/src/assembly/assembly.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<mainClass>com.example.MyApp</mainClass>
<executable>${env.JAVA_HOME}/bin/java</executable>
</configuration>
</plugin>
</plugins>
</build>
</project>