I am using Maven and when trying to turn it into a jar file it says build success but it says No sources to compile.
[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] ------------------------------------------------------------------------
This is the error which is shown and I do not know why this is being shown.
Maven requires a fixed structure of project.
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
You need moved you source files in src/main/java/...
It's need becose maven not know where you can keep *.class files, maven try find in "src/main/java", and not found.
This structure is contract
No sources to compile
is related to unit tests.
The production code is already compiled. It says:
Nothing to compile - all classes are up to date
If you really need a jar file of your application you may do this via 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>
Now run mvn clean install
and find a jar file under target
folder.
And make sure your project structure follows this standard .
Once you have your source and resources files in correct location, you can add maven-jar-plugin
in pom.xml and run command mvn jar:jar
src/main/java - sources
src/main/resources - resources
Reference : 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>
NOTE: I usually do not give non-documentation links because they may be deleted or expire but here is an example from where i learned long time back https://www.mkyong.com/maven/how-to-create-a-jar-file-with-maven/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.