Why doesn't maven include the JSP files in my jar?

12,148

Solution 1

My solution was to add the jsp files to src/main/webapp and to add the following snippet in the pom file:

<build>
    <resources>
      ...
      <resource>
        <directory>src/main/webapp</directory>
      </resource>
      ...
    </resources>
    ...
</build>

Solution 2

Try to place .jsp into src/main/resources, Maven ignores all but .java files in src/main/java

Share:
12,148
klactose
Author by

klactose

Just a guy trying to figure it all out while enjoying the journey!

Updated on June 05, 2022

Comments

  • klactose
    klactose almost 2 years

    I have an embedded jetty (version 8.1.8) web app I am packaging as a jar and which uses JSP for its frontend. It is built with maven version 3.0.3. The problem is that when I do: mvn package it is including everything except my *.jsp files. I've tried to relocate them many different places but no luck.

    I've tried to add <include>src/main/java/**/*.jsp</include> to the maven-compiler-plugin section of my pom. But that had no effect either.

    Is there a way to be certain that jsp files get included?

  • klactose
    klactose about 11 years
    hmmm, just tried. Doesn't appear that the src/main/resources directory is being added to the jar either. I'm checking contents using the jar command
  • Joakim Erdfelt
    Joakim Erdfelt about 11 years
    Use $ mvn clean package to create the jar file, then test its contents. One of your configured plugins is causing the problems you are seeing. Start with no <plugins>, then add each plugin back until it breaks again. Then fix that specific plugin's configuration.
  • klactose
    klactose about 11 years
    so in order to get the src/main/resources folder to show up in my jar I actually had to add that folder to the pom like so: <build><resources><resource>src/main/resources</resource></r‌​esources>...</build>
  • Evgeniy Dorofeev
    Evgeniy Dorofeev about 11 years
    src/main/resources is default. it's not the directory itself but its content that gets to jar. if you place 1.jsp in src/main/resources you'll get 1.jsp in jar root
  • end-user
    end-user over 5 years
    I found that this wipes out the regular resource inclusion unless you do a second <resource> block for that too.
  • klactose
    klactose over 5 years
    @end-user the ... after the resource block was to indicate that this was simply an additional resource, not replacing any existing resources. However, I've added another set of ellipses preceding the resource block that hopefully makes that more clear.
  • end-user
    end-user over 5 years
    No, I understand the meaning of an ellipsis is to indicate other elements may be present. What I'm suggesting is (I believe) the default behavior of Maven, without specifying a <resources> block, is to include whatever's in src/main/resources. However if you direct it to webapp, it overrides the default, requiring you specify both (if you need both).