Why doesn't maven include the JSP files in my jar?
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
klactose
Just a guy trying to figure it all out while enjoying the journey!
Updated on June 05, 2022Comments
-
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 themaven-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 about 11 yearshmmm, 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 about 11 yearsUse
$ 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 about 11 yearsso 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></resources>...</build>
-
Evgeniy Dorofeev about 11 yearssrc/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 over 5 yearsI found that this wipes out the regular resource inclusion unless you do a second
<resource>
block for that too. -
klactose over 5 years@end-user the
...
after theresource
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 over 5 yearsNo, 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 insrc/main/resources
. However if you direct it towebapp
, it overrides the default, requiring you specify both (if you need both).