我已经浏览了StackOverflow上的所有内容,但无法找到答案。我刚刚构建了一台新机器,并且我有一些编译和构建在以前的安装上的项目。但我的新机器不会。一切似乎正在建设(没有生成错误,包括正确的依赖项),但从我的项目实际的类文件(我写的代码)不包括在jar中。然后我创建了一个简单的helloWorld项目,其中包含一些最小的POM文件,以查看问题是否仍然存在。我从命令行完成构建,以消除等式中的错误。Maven Build不包括jar文件中的.class文件
类代码
package com.zoverge.utils;
public class HelloWorld {
/**
* @param args
*/
public static void main(String[] args) {
String message = args[0];
System.out.println(message);
}
}
我的POM文件
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.zoverge.utils</groupId>
<artifactId>helloworld</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>Hello World</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.java.version>1.6</project.build.java.version>
<org.apache.maven.plugins.maven-compiler-plugin.version>2.5.1</org.apache.maven.plugins.maven-compiler-plugin.version>
</properties>
<build>
<plugins>
<!-- Maven will compile our source java classes using the "project.build.java.version"
specified -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${org.apache.maven.plugins.maven-compiler-plugin.version}</version>
<configuration>
<source>${project.build.java.version}</source>
<target>${project.build.java.version}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.zoverge.utils.HelloWorld</mainClass>
</manifest>
</archive>
<finalName>HelloWorld</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies/>
</project>
产生的构建产生2个jar文件(如预期)的HelloWorld-1.0.jar和的HelloWorld.jar。这两个jar都不包含HelloWorld.java的已编译类文件。我认为这对我的环境来说是一个问题,因为对于在其他开发机器上运行良好的其他项目,这种行为是相同的,但我似乎无法弄清楚其中的差异。我没有访问我以前的开发机器来比较配置。我的.m2/setting.xml基本上是空的。
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>${user.home}/.m2/repository</localRepository>
<interactiveMode/>
<usePluginRegistry/>
<offline/>
<pluginGroups/>
<servers/>
<mirrors/>
<proxies/>
<profiles/>
<activeProfiles/>
</settings>
奇怪的是,用Maven 3.0.4为我工作。 – 2013-02-15 20:52:09
深入挖掘我的Maven安装后,我发现了多个实例(3.0.3和2.2.1)。我需要清理这个,然后再试一次...... thx。 – 2013-02-15 21:04:07
没有运气。我做了一个完整的卸载并重新安装Maven并升级到最新的(3.0.4),我仍然得到一个没有类文件的jar,现在清单没有列出任何主类。 清单-版本:1.0 归档-版本:丛归档 创建-者:阿帕奇Maven的 内置者:johnblakie 内建的jdk:1.6.0_37 – 2013-02-15 23:06:58