spring-attic / gs-maven

Building Java Projects with Maven :: Learn how to build a Java project with Maven.

Home Page:https://spring.io/guides/gs/maven/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`mvn compile` does not create 'target\classes' directory

HarshKhatore opened this issue · comments

I was going through the tutorial Building Java Projects with Maven on https://spring.io/guides/gs/maven/. It mentions that after mvn compile, target\classes directory will be created, but that does not happen. I get this directory after mvn package command and it only contains .jar files. Am I missing something?

$ ./mvnw compile
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.636 s
[INFO] Finished at: 2019-07-14T22:10:24+01:00
[INFO] Final Memory: 13M/212M
[INFO] ------------------------------------------------------------------------
complete$ find target/
target/
target/classes
target/classes/hello
target/classes/hello/Greeter.class
target/classes/hello/HelloWorld.class
target/generated-sources
target/generated-sources/annotations
target/maven-status
target/maven-status/maven-compiler-plugin
target/maven-status/maven-compiler-plugin/compile
target/maven-status/maven-compiler-plugin/compile/default-compile
target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst

What am I missing?

I'm having the same problem as HarshKhatore.

On my machine it works correctly, but building a docker image fails.
On my laptop:

Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: /usr/local/Cellar/maven/3.8.1/libexec
Java version: 15.0.2, vendor: N/A, runtime: /usr/local/Cellar/openjdk/15.0.2/libexec/openjdk.jdk/Contents/Home
Default locale: en_CA, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.7", arch: "x86_64", family: "mac"

In docker:

Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: /usr/share/maven
Java version: 11.0.11, vendor: AdoptOpenJDK, runtime: /opt/java/openjdk
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.10.25-linuxkit", arch: "amd64", family: "unix"

My dockerfile:

FROM maven:3.8.1-adoptopenjdk-11

WORKDIR /jenkins-plugin/

COPY src/* ./src/
COPY pom.xml .
COPY Jenkinsfile .

RUN mvn verify
RUN mvn package

I think this will work in Java 11 just like java 15. Am I missing something?

I figured out my issue. In my case src/main/java/ and src/main/resources/ were missing (I had copied them into the wrong place). I was seeing this buried in the compile output:

[INFO] skip non existing resourceDirectory /my-jenkins-plugin/src/main/resources

In docker neither COPY src/* ./src/ or COPY src/ . did what I expected. The right way is COPY src/ ./src/