繁体   English   中英

Maven Build不包括jar中的.class文件

[英]Maven Build is not including .class file in jar

我查看了StackOverflow上可以找到的所有内容,但我找不到答案。 我刚刚建立了一台新机器,我有一些项目可以在以前的安装中编译和构建。 但我的新机器不会。 一切似乎正在构建正确(没有构建错误,正确包含依赖项),但我的项目中的实际类文件(我写的代码)不包含在jar中。 然后我创建了一个简单的helloWorld项目,其中包含一些最小的POM文件,可以看到问题仍然存在。 我从命令行进行构建,将eclipse从等式中取出。

班级代码

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假定/ src / main / java /结构。 我的结构不同,并没有在POM.xml中重写。 匹配标准路径或覆盖POM.xml中的路径修复了问题。

暂无
暂无

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

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