Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven WAR - sources are not getting compiled

Greetings,

I am trying to build my web application with maven but I ran into some difficulties.

Maven assembles my war file and puts everything into its place except for the compiled classes. It seems like my sources are not even getting compiled.

My folder structure looks like this:

         src
         src/main
         src/main/java
         src/main/java/com
         src/main/java/com/test
         src/main/java/com/test/applications
         src/main/java/com/test/applications/TestApplication.java
         src/main/resources
         src/main/webapp
         src/main/webapp/media
         src/main/webapp/media/someimages.jpg
         src/main/webapp/styles
         src/main/webapp/styles/somecss.css
         src/main/webapp/WEB-INF
         src/main/webapp/WEB-INF/web.xml
         src/main/webapp/scripts
         src/main/webapp/scripts/jquery
         src/main/webapp/scripts/jquery/jquery-1.5.js
         pom.xml

and my pom.xml looks like this:

<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>com.test</groupId>
  <artifactId>TestApp</artifactId>
  <packaging>war</packaging>

  <version>0.0.1-SNAPSHOT</version>
  <name>TestApp Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <build>
    <finalName>TestApp</finalName>
  </build>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

The assembled ware file looks ok except that the WEB-INF/classes folder is empty. I'm building with Jenkins and Maven 3.0.2.

Any help would be very much appreaciated.

Best Regards, Chris

like image 271
csupnig Avatar asked May 08 '11 20:05

csupnig


2 Answers

The problem could be solved:

As mentioned in the comment I had still some old configuration for the jenkins build job where it would use the goal war:war to build the project.

After removing this it worked fine.

like image 51
csupnig Avatar answered Nov 02 '22 16:11

csupnig


I had the same problem(except that I'm not using jekins). NOTE: I used the maven webapp creation:

mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp -DgroupId=myGroupID -DartifactId=myArtifactID

The webapp project folder structure had a this folder: 'src/main/resources' wich all my sources(.java files) were in.

as i changed the 'resources' folder name to 'java'(meaning 'src/main/java') by a friend sugestion, all I had to do is to call 'mvn clean install' to have a war file containig compiled classes.

hope my answer is detailed enough....

like image 32
Yarden Bar Avatar answered Nov 02 '22 15:11

Yarden Bar