vpalle
vpalle

Reputation: 945

maven, jsp files in dependency

I'm using maven2 for dependency management. I have one project that contains some Java files and some jsp files and another project, a web project, that depends on the first project. How do I access the jsp files from the web project?

I can see that the jsp files are added to 1-0-SNAPSHOT-sources.jar and not 1-0-SNAPSHOT.jar (which is added as a dependency in the web projects pom.xml).

Upvotes: 10

Views: 9870

Answers (3)

Gustavo Matias
Gustavo Matias

Reputation: 3608

I wanted some files from a dependency JAR project into my WEB project.

I've done this way so I could have the files not only when packaging the WAR but also when running the maven servlet container plugin (i.e. jetty:run or tomcat:run).

So here's what worked for me:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.1</version>
    <executions>
        <execution>
            <id>copy-files-to-webapp-directory</id>
            <phase>compile</phase>
            <goals>
                <goal>unpack</goal>
            </goals>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>com.my.project</groupId>
                        <artifactId>my-amazing-project</artifactId>
                        <type>jar</type>
                        <overWrite>true</overWrite>
                        <outputDirectory>src/main/webapp</outputDirectory>
                        <includes>**/*.jsp, **/*.css, **/*.png</includes>
                    </artifactItem>
                </artifactItems>
            </configuration>
        </execution>
    </executions>
</plugin>

Hope that helps anyone looking for a similar solution

Upvotes: 0

user177165
user177165

Reputation:

The problem with that solution is that when developping with Eclipse, the project doesn't handle the overlay. So, the jsp are not accessible.

Upvotes: 0

Thomas Marti
Thomas Marti

Reputation: 940

I think the correct Maven-way to do it would be to put the JSP files in your web project under /src/main/webapp. If that for some reason is not possible, you could use the Maven Dependency Plugin to copy the needed files into your webapp. Or, if you have a WAR project anyway, you could use an Overlay to copy the JSP-Files. The second option (which I'd recommend), would look something like this:

    <build>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-war-plugin</artifactId>
          <configuration>
            <overlays>
              <overlay>
                <groupId>myGroupId</groupId>
                <artifactId>myArtifactId</artifactId>
                <type>jar</type>
                <includes>
                  <include>**/*.jsp</include>
                </includes>
                <targetPath>WEB-INF/pages</targetPath>
              </overlay>
            </overlays>
          </configuration>
        </plugin>
      </plugins>
    </build>

Upvotes: 14

Related Questions