【问题标题】:Maven package not outputting .class file?Maven包不输出.class文件?
【发布时间】:2020-07-19 17:51:54
【问题描述】:

我正在使用 Maven 3.6.3 编译、构建并将我的项目打包到 jar 中,运行 mvn package 命令后没有 .classjar 中的 /em> 文件都是在编译时生成的 .java 文件,所以这不是正确的输出,正确的方法是什么?

下面是我的文件夹结构

ProjectA
-- src
      com
        hcc
          Folder1
            a.java
            b.java
-- META-INF
      services
        service1.txt
        service2.txt
-- pom.xml

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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>Utility</groupId>
    <artifactId>UtilityDev</artifactId>
    <packaging>jar</packaging>
    <version>1.0.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <base.path>${project.basedir}/../ThirdParty Jars</base.path>
    </properties>

    <build>
        <finalName>Utility</finalName>
        <resources>
            <resource>
                <directory>src</directory>
            </resource>
            <resource>
                <directory>META-INF</directory>
                <includes>
                    <include>**services/**</include>
                </includes>
                <targetPath>META-INF</targetPath>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.2.0</version>
                <configuration>
                    <excludes>
                        <exclude>*.properties</exclude>
                    </excludes>
                    <archive>
                        <addMavenDescriptor>false</addMavenDescriptor>
                        <manifest>
                            <addDefaultImplementationEntries>false</addDefaultImplementationEntries>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>xyz</groupId>
            <artifactId>xyz</artifactId>
            <version>123</version>
            <scope>system</scope>
            <systemPath>${base.path}/CommonLib/xyz.jar</systemPath>
        </dependency>
    </dependencies>
</project>

【问题讨论】:

    标签: java maven jar pom.xml


    【解决方案1】:

    不要将src 添加到资源中。

    相反,将您的源代码放入src/main/java,Maven 会自动找到它。

    【讨论】:

    • 感谢@JF,但我们不能像main/java 那样将我们的文件夹放在里面,因为它是一个自定义结构,所以有没有其他方法可以做到这一点或在 pom 文件中调整一些东西。
    • 首先,“我们不能”不是一个论据,至少在您与您的经理讨论之前。也就是说,您可以将&lt;build&gt; 中的&lt;sourceDirectory&gt; 设置为不同的源目录。
    • 嘿@JF,我们的团队正在遵循这个自定义结构,所以我建议遵循标准结构,但他们没有迁移,需要从现有项目中打包。我在build 中提到了src,但它没有输出.class 文件。
    • 所以你添加了&lt;sourceDirectory&gt;src&lt;/sourceDirectory&gt;?
    • 嘿@JF 只是一个快速的问题,我可以在 pom 文件中设置多个编码。
    猜你喜欢
    • 2013-01-31
    • 1970-01-01
    • 2021-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-21
    • 2012-09-17
    • 1970-01-01
    相关资源
    最近更新 更多