英文:
Maven package not outputting .class file?
问题
我正在使用Maven 3.6.3编译、构建并将我的项目打包成jar,在运行mvn package命令后,jar内部没有任何*.class文件,只有在编译时生成的.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>
英文:
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>
答案1
得分: 1
不要将src
添加到资源中。
相反,将您的源代码放入src/main/java
,Maven会自动找到它。
英文:
Don't add src
to the resources.
Instead, put your source code into src/main/java
and Maven will find it automatically.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论