我正在使用Maven,并且在尝试将其转换为jar文件时,它表示构建成功,但它表示无需编译源。
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building UrbanAC Booking Manager 1.2.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ UrbanAC -- -
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 24 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ UrbanAC ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ UrbanAC ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\Akhil Maganti\eclipse- workspace\New\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ UrbanAC ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ UrbanAC ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ UrbanAC ---
[INFO] Building jar: C:\Users\Akhil Maganti\eclipse-workspace\New\target\UrbanAC-1.2.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.413 s
[INFO] Finished at: 2017-11-11T00:19:22+00:00
[INFO] Final Memory: 11M/245M
[INFO] ------------------------------------------------------------------------
答案 0 :(得分:3)
Maven需要一个固定的项目结构。
src/main/java - Application/Library sources
src/main/resources - Application/Library resources
...
https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html
您需要在src / main / java /...
中移动源文件需要因为maven不知道你在哪里可以保存* .class文件,maven尝试在“src / main / java”中查找,但找不到。
这个结构是契约
答案 1 :(得分:1)
No sources to compile
与单元测试有关。
生产代码已经编译完毕。它说:
Nothing to compile - all classes are up to date
如果您确实需要应用程序的jar文件,可以通过maven-assembly-plugin:
执行此操作 <plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>your.main.class</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
现在运行mvn clean install
并在target
文件夹下找到一个jar文件。
确保您的项目结构遵循此standard。
答案 2 :(得分:1)
将源文件和资源文件放在正确的位置后,可以在pom.xml中添加maven-jar-plugin
并运行命令mvn jar:jar
src/main/java - sources
src/main/resources - resources
参考:https://maven.apache.org/plugins/maven-jar-plugin/
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
...
</plugin>
</plugins>
</build>
...
</project>
注意:我通常不提供非文档链接,因为它们可能会被删除或过期,但这里是我长时间回来学习的例子https://www.mkyong.com/maven/how-to-create-a-jar-file-with-maven/