Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven: JspC should use external JSP-files

Tags:

maven

pom.xml

We're using Maven 3 and I'm facing a project that has JSP-files and also uses "global" JSP-files stored in a different project. This works nicely when using maven-war-plugin and webResources. All JSP-files find their way into the WAR-file.

The new idea is to pre-compile all the JSPs. The obvious choice is to use jspc-maven-plugin. However, that doesn't include the external JSPs when it compiles the project-local JSPs.

Here's the snippet from the pom.xml:

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jspc-maven-plugin</artifactId>
    <executions>
      <execution>
        <id>jspc</id>
        <goals>
          <goal>compile</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1</version>
    <configuration>
      <warName>${pom.groupId}.${pom.artifactId}-0.0.1-SNAPSHOT</warName>
      <webXml>${basedir}/target/jspweb.xml</webXml>
      <webResources>
        <resource>
          <directory>../name.of.external.project/src/global/webapp</directory>
        </resource>
      </webResources>
    </configuration>
  </plugin>

The error is

[ERROR] Failed to execute goal org.codehaus.mojo:jspc-maven-plugin:1.4.6:compile (jspc) on project internal.project: JSPC Error: file:C:/workspace/name.of.internal.project/src/main/webapp/WEB-INF/views/show.jsp(2,0) File "/WEB-INF/views/../jspGlobal/jsp-declaration.jspf" not found -> [Help 1]

The jspGlobal-directory would get copied with the <directory>../name.of.external.project/src/global/webapp</directory>-line above.

What's missing to include the external JSPs in JspC?


EDIT: Thanks to prunge's and Raghuram's input I looked deeper into sources and JavaDocs. I noticed that the mentioned sources requires a FileSet which does NOT allow a list of directories. And since sources is also not a list, I see no chance how I can specify more than one JSP-source directory. I even tried to copy the <plugin>-element, but that didn't help. My current situation is this:

  <plugin>
    <groupId>org.codehaus.mojo.jspc</groupId>
    <artifactId>jspc-maven-plugin</artifactId>
    <version>2.0-alpha-3</version>
    <executions>
      <execution>
        <id>jspc</id>
        <goals>
          <goal>compile</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <sources>
        <directory>${basedir}/../name.of.external.project/src/global/webapp</directory>
      </sources>
<!-- the later mentioned <sources> gets picked
      <sources>
        <directory>${basedir}/src/main/webapp</directory>
      </sources>
-->
      <!-- 1.6 doesn't work!? Something lower than 1.5 seems to be the default -->
      <source>1.5</source>
      <target>1.5</target>
    </configuration>
    <dependencies>
      <dependency>
        <groupId>org.codehaus.mojo.jspc</groupId>
        <artifactId>jspc-compiler-tomcat6</artifactId>
        <version>2.0-alpha-3</version>
      </dependency>
    </dependencies>
  </plugin>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1</version>
    <configuration>
      <warName>${pom.groupId}.${pom.artifactId}-0.0.1-SNAPSHOT</warName>
      <webXml>${basedir}/target/jspweb.xml</webXml>
      <webResources>
        <resource>
          <directory>../name.of.external.project/src/global/webapp</directory>
        </resource>
      </webResources>
    </configuration>
  </plugin>

Now the external JSPs are compiled into the target-path of the current project. Now I need a way to compile the JSPs of the current project. How do I do this?

BTW, if I switch the <sources> to the line for the current project I get the same error as mentioned earlier.

like image 994
sjngm Avatar asked Nov 05 '22 15:11

sjngm


2 Answers

Perhaps you could try with the latest version of jspc-maven-plugin, which is 2.0-alpha-3. Do note that the usage is a little different from the earlier version.

like image 62
Raghuram Avatar answered Nov 09 '22 12:11

Raghuram


Looking at the source code of CompilationMojoSupport, I see a sources property of type FileSet. You might be able to configure this in the configuration of the plugin to add additional source directories. It looks like by default it uses ${project.basedir}/src/main/webapp regardless of the configuration of the WAR plugin.

like image 34
prunge Avatar answered Nov 09 '22 12:11

prunge