Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

unable to get maven to compile JSPs

Avatar

Level 1

Hi,

I'm using AEM 5.6.1 and I've followed the instructions on http://dev.day.com/docs/en/cq/aem-how-tos/development/how-to-build-aem-projects-using-apache-maven.h....

I'm trying to get my JSPs to compile as the "content" project of my multi-module project. Because some of my JSPs reference /libs/foundation/global.jsp, I had to include that file in the compilation. And because one of my JSPs overrides one of the /libs/foundations/components JSPs, I had to include that, too, which of course introduced a bunch of additional dependencies that I needed to resolve.

I painstakingly added the necessary dependencies to the pom.xml file, attempting to build each time and using the "depfind" feature to figure out which one to add every time I got a compilation error that a particular class could not be resolved. I finally got all of the class resolution errors sorted out.

Now I'm faced with new errors where the compiler can't resolve, among other things, "xssAPI," which seems to be referenced from many JSPs but never actually defined anywhere. The errors are shown below. Any ideas? I'd really like to get this to work, as my next step is to get JSP auto-complete to work in Eclipse. But even just having it work in the maven build would be a good start. This is Adobe's out-of-the-box stuff for the most part!

[ERROR] Compilation Failure org.apache.sling.scripting.jsp.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 3 in the jsp file: /libs/foundation/components/profile/form/formrowtext.jsp xssAPI cannot be resolved 1: <%@page session="false"%><div class="form_row"> 2:       <div class="form_leftcol"> 3:           <div class="form_leftcollabel"><label for="<%= xssAPI.encodeForHTMLAttr(path) %>"><%= xssAPI.encodeForHTML(title) %></label></div> 4:           <div class="form_leftcolmark <%= required ? "form_required" : ""%>"><%= required ? "*" : " " %></div> 5:       </div> 6:       <div class="form_rightcol"><% An error occurred at line: 3 in the jsp file: /libs/foundation/components/profile/form/formrowtext.jsp path cannot be resolved 1: <%@page session="false"%><div class="form_row"> 2:       <div class="form_leftcol"> 3:           <div class="form_leftcollabel"><label for="<%= xssAPI.encodeForHTMLAttr(path) %>"><%= xssAPI.encodeForHTML(title) %></label></div> 4:           <div class="form_leftcolmark <%= required ? "form_required" : ""%>"><%= required ? "*" : " " %></div> 5:       </div> 6:       <div class="form_rightcol"><% An error occurred at line: 3 in the jsp file: /libs/foundation/components/profile/form/formrowtext.jsp title cannot be resolved 1: <%@page session="false"%><div class="form_row"> 2:       <div class="form_leftcol"> 3:           <div class="form_leftcollabel"><label for="<%= xssAPI.encodeForHTMLAttr(path) %>"><%= xssAPI.encodeForHTML(title) %></label></div> 4:           <div class="form_leftcolmark <%= required ? "form_required" : ""%>"><%= required ? "*" : " " %></div> 5:       </div> 6:       <div class="form_rightcol"><% An error occurred at line: 4 in the jsp file: /libs/foundation/components/profile/form/formrowtext.jsp required cannot be resolved 1: <%@page session="false"%><div class="form_row"> 2:       <div class="form_leftcol"> 3:           <div class="form_leftcollabel"><label for="<%= xssAPI.encodeForHTMLAttr(path) %>"><%= xssAPI.encodeForHTML(title) %></label></div> 4:           <div class="form_leftcolmark <%= required ? "form_required" : ""%>"><%= required ? "*" : " " %></div> 5:       </div> 6:       <div class="form_rightcol"><% 7:       final String rows = properties.get("rows", ""); An error occurred at line: 7 in the jsp file: /libs/foundation/components/profile/form/formrowtext.jsp properties cannot be resolved 4:           <div class="form_leftcolmark <%= required ? "form_required" : ""%>"><%= required ? "*" : " " %></div> 5:       </div> 6:       <div class="form_rightcol"><% 7:       final String rows = properties.get("rows", ""); 8:       if ( rows.length() == 0 || rows.equals("1") ) { 9:           %><input class="geo textinput" <% 10:              %>name="<%= xssAPI.encodeForHTMLAttr(nodeName) %>" <% An error occurred at line: 10 in the jsp file: /libs/foundation/components/profile/form/formrowtext.jsp nodeName cannot be resolved 7:       final String rows = properties.get("rows", ""); 8:       if ( rows.length() == 0 || rows.equals("1") ) { 9:        %><input class="geo textinput" <% 10:              %>name="<%= xssAPI.encodeForHTMLAttr(nodeName) %>" <% 11:              %>value="<%= xssAPI.encodeForHTMLAttr(value)%>" <% 12:              %>size="<%= xssAPI.getValidInteger(cols, 35) %>" <% 13:                 if (width.length() > 0) { An error occurred at line: 12 in the jsp file: /libs/foundation/components/profile/form/formrowtext.jsp cols cannot be resolved 9:        %><input class="geo textinput" <% 10:              %>name="<%= xssAPI.encodeForHTMLAttr(nodeName) %>" <% 11:              %>value="<%= xssAPI.encodeForHTMLAttr(value)%>" <% 12:              %>size="<%= xssAPI.getValidInteger(cols, 35) %>" <% 13:                 if (width.length() > 0) { 14:                     %>style="width:<%= xssAPI.getValidInteger(width, 100) %>px;" <% 15:                 }
1 Accepted Solution

Avatar

Correct answer by
Level 5

Personally I have never used jspc to compile my jsps during build time due to some reasons. I tried it today and it seems to be working for me with following dependencies 

http://wemcode.wemblog.com/parent-pom

And following plugin definition

 <plugin>

                <artifactId>maven-resources-plugin</artifactId>

                <!-- ensure that the empty directories are copied -->

                <configuration>

                    <includeEmptyDirs>true</includeEmptyDirs>

                </configuration>

 

                <executions>

                 

                     <execution>

                          <id>copy-resources</id>

                          <phase>generate-sources</phase>

                          <goals>

                            <goal>copy-resources</goal>

                          </goals>

                          <configuration>

                            <outputDirectory>${project.build.directory}/jsps-to-compile</outputDirectory>

                            <resources>

                              <resource>

                                <directory>jcr_root</directory>

                                <excludes>

                                    <exclude></exclude>

                                </excludes>

                               <includes>  

                                      <include>apps/**</include>  

                                      <include>libs/foundation/global.jsp</include>

                                </includes>  

                                

                              </resource>

                            </resources>

                          </configuration>

                </execution>

                    

                    

                </executions>

            </plugin>

            

            

            <plugin>

                  <groupId>org.apache.sling</groupId>

                  <artifactId>maven-jspc-plugin</artifactId>

                  <version>2.0.6</version>

                  <executions>

                    <execution>

                      <id>compile-jsp</id>

                      <goals>

                        <goal>jspc</goal>

                      </goals>

                      <configuration>

                        <jasperClassDebugInfo>false</jasperClassDebugInfo>

                        <sourceDirectory>${project.build.directory}/jsps-to-compile</sourceDirectory>

                        <outputDirectory>${project.build.directory}/ignoredjspc</outputDirectory>

                      </configuration>

                    </execution>

                  </executions>

                </plugin>

                <plugin>

                  <artifactId>maven-clean-plugin</artifactId>

                  <executions>

                    <execution>

                      <id>remove-compiled-jsps</id>

                      <goals>

                        <goal>clean</goal>

                      </goals>

                      <phase>process-classes</phase>

                      <configuration>

                        <excludeDefaultDirectories>true</excludeDefaultDirectories>

                        <filesets>

                          <fileset>

                            <directory>${project.build.directory}/jsps-to-compile</directory>

                            <directory>${project.build.directory}/ignoredjspc</directory>

                          </fileset>

                        </filesets>

                      </configuration>

                    </execution>

                  </executions>

           </plugin>

 

 

     Yogesh

View solution in original post

5 Replies

Avatar

Level 5

Hello,

XssAPI should be part of /libs/foundation/global.jsp. Can you please make sure that you have <%@include file="/libs/foundation/global.jsp"%> included in your JSP file. 

Are you trying to compile your JSP from eclipse or as part of build ? Or you are getting this error while rendering a page after deployment ? Trying to understand pom.xml role here for jsp.

Yogesh

Avatar

Level 1

Yogesh Upadhyay wrote...

Hello,

XssAPI should be part of /libs/foundation/global.jsp. Can you please make sure that you have <%@include file="/libs/foundation/global.jsp"%> included in your JSP file. 

Are you trying to compile your JSP from eclipse or as part of build ? Or you are getting this error while rendering a page after deployment ? Trying to understand pom.xml role here for jsp.

Yogesh

 

I am indeed including /libs/foundation/global.jsp in my own JSPs. I don't see xssAPI defined directly in global.jsp. If it is defined via the <cq:defineObjects /> tag, please let me know what I need to include in order to resolve xssAPI.

Thanks

Avatar

Level 5

Yes xssAPI is part of <cq:defineObjects /> which is already included in /libs/foundation/global.jsp so, including /libs/foundation/global.jsp should work.

http://dev.day.com/docs/en/cq/current/javadoc/com/day/cq/wcm/tags/DefineObjectsTag.html

Can you add

<dependency>

<groupId>com.day.cq.wcm</groupId>

<artifactId>cq-wcm-taglib</artifactId>

<version>5.6.4</version>

<scope>provided</scope>

</dependency>

In your pom.xml to see if it help to resolve compilation issue during build. Note that this is added in later version of CQ so if you are trying to reference old version of cq-wcm-taglib you might not find it.

Yogesh

Avatar

Level 1

Ha, believe me, I've got every conceivable dependency in there. Here's my main pom.xml (the content project's pom.xml has the corresponding entries).

<dependencies> <dependency> <groupId>com.day.cq.wcm</groupId> <artifactId>cq-wcm-mobile-api</artifactId> <version>5.5.2</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.day.cq.wcm</groupId> <artifactId>cq-wcm-mobile-core</artifactId> <version>5.6.2</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.adobe.granite</groupId> <artifactId>com.adobe.granite.license</artifactId> <version>0.8.2</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.abdera</groupId> <artifactId>abdera-extensions-media</artifactId> <version>1.0-R783018</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.atom.taglib</artifactId> <version>0.9.0-R988585</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.day.cq.wcm</groupId> <artifactId>cq-wcm-taglib</artifactId> <version>5.6.4</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.auth.core</artifactId> <version>1.1.2</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.day.cq</groupId> <artifactId>cq-tagging</artifactId> <version>5.6.4</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.adobe.granite</groupId> <artifactId>com.adobe.granite.security.user</artifactId> <version>0.1.6</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.adobe.cq.commerce</groupId> <artifactId>cq-commerce-core</artifactId> <version>5.6.18</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.day.cq</groupId> <artifactId>cq-personalization</artifactId> <version>5.6.8</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.day.cq.wcm</groupId> <artifactId>cq-wcm-foundation</artifactId> <version>5.6.4</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.day.cq.wcm</groupId> <artifactId>cq-wcm-webservice-support</artifactId> <version>5.6.4</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.day.cq.dam</groupId> <artifactId>cq-dam-commons</artifactId> <version>5.6.8</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.day.cq.dam</groupId> <artifactId>cq-dam-video</artifactId> <version>5.6.2</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.day.cq</groupId> <artifactId>cq-analytics</artifactId> <version>5.6.16</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.day.cq.dam</groupId> <artifactId>cq-dam-api</artifactId> <version>5.6.6</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.adobe.granite</groupId> <artifactId>com.adobe.granite.ui.commons</artifactId> <version>5.5.76</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.day.commons</groupId> <artifactId>day-commons-text</artifactId> <version>1.1.8</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.adobe.granite</groupId> <artifactId>com.adobe.granite.xssprotection</artifactId> <version>5.5.24</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.day.cq</groupId> <artifactId>cq-quickstart-product-dependencies</artifactId> <version>5.6.1</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.core</artifactId> <version>4.2.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.compendium</artifactId> <version>4.2.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.felix</groupId> <artifactId>org.apache.felix.scr.annotations</artifactId> <version>1.6.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>biz.aQute</groupId> <artifactId>bndlib</artifactId> <version>1.43.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.5.10</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.jcr</groupId> <artifactId>jcr</artifactId> <version>2.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.api</artifactId> <version>2.2.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.jcr.api</artifactId> <version>2.1.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.1</version> <scope>test</scope> </dependency> </dependencies>

Avatar

Correct answer by
Level 5

Personally I have never used jspc to compile my jsps during build time due to some reasons. I tried it today and it seems to be working for me with following dependencies 

http://wemcode.wemblog.com/parent-pom

And following plugin definition

 <plugin>

                <artifactId>maven-resources-plugin</artifactId>

                <!-- ensure that the empty directories are copied -->

                <configuration>

                    <includeEmptyDirs>true</includeEmptyDirs>

                </configuration>

 

                <executions>

                 

                     <execution>

                          <id>copy-resources</id>

                          <phase>generate-sources</phase>

                          <goals>

                            <goal>copy-resources</goal>

                          </goals>

                          <configuration>

                            <outputDirectory>${project.build.directory}/jsps-to-compile</outputDirectory>

                            <resources>

                              <resource>

                                <directory>jcr_root</directory>

                                <excludes>

                                    <exclude></exclude>

                                </excludes>

                               <includes>  

                                      <include>apps/**</include>  

                                      <include>libs/foundation/global.jsp</include>

                                </includes>  

                                

                              </resource>

                            </resources>

                          </configuration>

                </execution>

                    

                    

                </executions>

            </plugin>

            

            

            <plugin>

                  <groupId>org.apache.sling</groupId>

                  <artifactId>maven-jspc-plugin</artifactId>

                  <version>2.0.6</version>

                  <executions>

                    <execution>

                      <id>compile-jsp</id>

                      <goals>

                        <goal>jspc</goal>

                      </goals>

                      <configuration>

                        <jasperClassDebugInfo>false</jasperClassDebugInfo>

                        <sourceDirectory>${project.build.directory}/jsps-to-compile</sourceDirectory>

                        <outputDirectory>${project.build.directory}/ignoredjspc</outputDirectory>

                      </configuration>

                    </execution>

                  </executions>

                </plugin>

                <plugin>

                  <artifactId>maven-clean-plugin</artifactId>

                  <executions>

                    <execution>

                      <id>remove-compiled-jsps</id>

                      <goals>

                        <goal>clean</goal>

                      </goals>

                      <phase>process-classes</phase>

                      <configuration>

                        <excludeDefaultDirectories>true</excludeDefaultDirectories>

                        <filesets>

                          <fileset>

                            <directory>${project.build.directory}/jsps-to-compile</directory>

                            <directory>${project.build.directory}/ignoredjspc</directory>

                          </fileset>

                        </filesets>

                      </configuration>

                    </execution>

                  </executions>

           </plugin>

 

 

     Yogesh