Naveen Kumar
Naveen Kumar

Reputation: 1432

Maven package not outputting .class file?

I am using Maven 3.6.3 to compile, build and package my project into jar, after running mvn package command so there are no .class files inside the jar all are .java files which were generated at the time of compilation so which is not the correct output, what is the correct way to do it?

Below is my folder structure

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>

Upvotes: 1

Views: 479

Answers (1)

J Fabian Meier
J Fabian Meier

Reputation: 35853

Don't add src to the resources.

Instead, put your source code into src/main/java and Maven will find it automatically.

Upvotes: 1

Related Questions