在CQ5 Archetype中使用Jsp时,在Maven项目中找不到global.jsp?

时间:2015-01-08 05:16:49

标签: java eclipse jsp maven cq5

我创建了多模块CQ5 Maven项目。我的Cq版本是5.5,Java版本是6。

这些是我遵循的步骤。

  1. 创建了maven多模块CQ maven项目
  2. 在eclipse中导入它
  3. 使用VLT将现有项目从存储库导入maven。
  4. 将项目转换为分面形式,以便捆绑部分正常工作。
  5. 内容模块中,我尝试使用JspC插件,我在各自的POM文件中添加了正确的插件信息和依赖项。
  6. 问题是当我编译JspC时发现找不到global.jsp

    所以我也在我的项目中导入/ libs并确保libs不包含在内置中。通过排除/ libs文件夹。我引用了这个链接Adding /libs

    我的JSP在其中具有默认的自动完成功能,但它们无法识别任何CQ对象,例如<cq:defineObjects /> 为什么?

    中定义的CQ对象

    我提到了此链接Autocomplete in JSP

    我的目录结构

    enter image description here

    我的内容POM如下

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <!-- ====================================================================== -->
        <!-- P A R E N T P R O J E C T D E S C R I P T I O N -->
        <!-- ====================================================================== -->
        <parent>
            <groupId>supplierportal</groupId>
            <artifactId>supplierportal</artifactId>
            <version>1.1-SNAPSHOT</version>
        </parent>
    
        <!-- ====================================================================== -->
        <!-- P R O J E C T D E S C R I P T I O N -->
        <!-- ====================================================================== -->
    
        <artifactId>supplierportal-content</artifactId>
        <packaging>content-package</packaging>
        <name>Supplier Portal Package</name>
    
        <dependencies>
            <dependency>
                <groupId>${project.groupId}</groupId>
                <artifactId>supplierportal-bundle</artifactId>
                <version>${project.version}</version>
            </dependency>
    
            <!-- My Dependencies -->
            <!-- Dependencies for Maven JSPC Starts -->
            <dependency>
                <groupId>org.apache.sling</groupId>
                <artifactId>org.apache.sling.jcr.jcr-wrapper</artifactId>
                <version>2.0.0</version>
                <!-- javax.jcr -->
            </dependency>
            <dependency>
                <groupId>org.apache.sling</groupId>
                <artifactId>org.apache.sling.api</artifactId>
                <version>2.2.0</version>
            </dependency>
            <dependency>
                <groupId>com.day.cq</groupId>
                <artifactId>cq-commons</artifactId>
                <version>5.5.0</version>
                <!-- com.day.cq.commons -->
            </dependency>
            <dependency>
                <groupId>com.day.cq.wcm</groupId>
                <artifactId>cq-wcm-commons</artifactId>
                <version>5.5.2</version>
                <!-- com.day.cq.wcm.commons -->
            </dependency>
            <dependency>
                <groupId>com.day.cq.wcm</groupId>
                <artifactId>cq-wcm-api</artifactId>
                <version>5.5.0</version>
                <!-- com.day.cq.wcm.api -->
            </dependency>
            <dependency>
                <groupId>com.day.commons</groupId>
                <artifactId>day-commons-jstl</artifactId>
                <version>1.1.4</version>
                <!-- javax.servlet.jsp.jstl.core -->
            </dependency>
            <dependency>
                <groupId>com.day.cq.wcm</groupId>
                <artifactId>cq-wcm-taglib</artifactId>
                <version>5.5.0</version>
                <!-- com.day.cq.wcm.tags -->
            </dependency>
            <dependency>
                <groupId>org.apache.sling</groupId>
                <artifactId>org.apache.sling.scripting.jsp.taglib</artifactId>
                <version>2.2.0</version>
                <!-- org.apache.sling.scripting.jsp.taglib -->
            </dependency>
            <dependency>
                <groupId>com.adobe.granite</groupId>
                <artifactId>com.adobe.granite.xssprotection</artifactId>
                <version>5.5.14</version>
                <!-- com.adobe.granite.xss -->
            </dependency>
            <dependency>
                <groupId>com.day.cq.wcm</groupId>
                <artifactId>cq-wcm-core</artifactId>
                <version>5.5.6</version>
                <!-- com.day.cq.wcm.core.components -->
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>3.0</version>
                <!-- org.apache.commons.lang3 -->
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>1.5.10</version>
            </dependency>
            <!-- Ends -->
    
        </dependencies>
        <build>
            <resources>
                <resource>
                    <directory>src/main/content/jcr_root</directory>
                    <filtering>false</filtering>
                    <excludes>
                        <exclude>**/.vlt</exclude>
                        <exclude>**/.vltignore</exclude>
                        <exclude>libs/</exclude>
                    </excludes>
                </resource>
    
    
    
            </resources>
    
        <!-- Autocomplete Plugin config comes here -->
            <!-- THis is Completely different Stuff... An Attempt to bring autocomplete feature in JSP -->
            <pluginManagement>
        <plugins>
          <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
          <plugin>
            <groupId>org.eclipse.m2e</groupId>
            <artifactId>lifecycle-mapping</artifactId>
            <version>1.0.0</version>
            <configuration>
              <lifecycleMappingMetadata>
                <pluginExecutions>
                  <pluginExecution>
                    <pluginExecutionFilter>
                      <groupId>org.apache.sling</groupId>
                      <artifactId>maven-jspc-plugin</artifactId>
                      <versionRange>[2.0.6,)</versionRange>
                      <goals>
                        <goal>jspc</goal>
                      </goals>
                    </pluginExecutionFilter>
                    <action>
                      <ignore/>
                    </action>
                  </pluginExecution>
                  <pluginExecution>
                    <pluginExecutionFilter>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-clean-plugin</artifactId>
                      <versionRange>[2.4.1,)</versionRange>
                      <goals>
                        <goal>clean</goal>
                      </goals>
                    </pluginExecutionFilter>
                    <action>
                      <ignore/>
                    </action>
                  </pluginExecution>
                </pluginExecutions>
              </lifecycleMappingMetadata>
            </configuration>
          </plugin>
        </plugins>
      </pluginManagement>
            <!-- Autocomplete Ends -->
    
    
        <!-- Ends Autocomplete -->
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <configuration>
                        <includeEmptyDirs>true</includeEmptyDirs>
                    </configuration>
                </plugin>
    
                <plugin>
                    <groupId>com.day.jcr.vault</groupId>
                    <artifactId>content-package-maven-plugin</artifactId>
                    <extensions>true</extensions>
                    <configuration>
                        <group>supplierportal</group>
                        <filterSource>src/main/content/META-INF/vault/filter.xml</filterSource>
                        <embeddeds>
                            <embedded>
                                <groupId>${project.groupId}</groupId>
                                <artifactId>supplierportal-bundle</artifactId>
                                <target>/apps/supplierportal/install</target>
                            </embedded>
                        </embeddeds>
                        <targetURL>http://${crx.host}:${crx.port}/crx/packmgr/service.jsp</targetURL>
                    </configuration>
                </plugin>
    
                <!-- Here I add code for JSPc Plugin -->
    
                <!-- start -->
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <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>src/main/content/jcr_root</directory>
                                        <excludes>
                                            <exclude>libs/**</exclude>
                                        </excludes>
                                    </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>
                <!-- end -->
    
                <!-- Ends JSPC plugin config -->
    
            </plugins>
    
        </build>
        <profiles>
            <profile>
                <id>autoInstallPackage</id>
                <build>
                    <plugins>
                        <plugin>
                            <groupId>com.day.jcr.vault</groupId>
                            <artifactId>content-package-maven-plugin</artifactId>
                            <executions>
                                <execution>
                                    <id>install-content-package</id>
                                    <phase>install</phase>
                                    <goals>
                                        <goal>install</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </build>
            </profile>
            <profile>
                <id>autoInstallPackagePublish</id>
                <build>
                    <plugins>
                        <plugin>
                            <groupId>com.day.jcr.vault</groupId>
                            <artifactId>content-package-maven-plugin</artifactId>
                            <executions>
                                <execution>
                                    <id>install-content-package-publish</id>
                                    <phase>install</phase>
                                    <goals>
                                        <goal>install</goal>
                                    </goals>
                                    <configuration>
                                        <targetURL>http://${publish.crx.host}:${publish.crx.port}/crx/packmgr/service.jsp</targetURL>
                                        <username>${publish.crx.username}</username>
                                        <password>${publish.crx.password}</password>
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </build>
            </profile>
        </profiles>
    
    </project>
    

2 个答案:

答案 0 :(得分:3)

@Vincent我无法在评论中回答你的问题所以我在这里给你一个详细的答案。

要导入/ lib /基础,您可以在

下创建一个EXTRA文件filter-vlt.xml
{yourproject}\content\src\main\content\META-INF\vault\filter-vlt.xml

filter-vlt.xml 中,您必须输入

<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
    <filter root="/libs/foundation"/>
    <filter root="/apps/myapp"/>
    <filter root="/etc/designs/myapp"/>
     <filter root="/etc/designs/bootstrap-custom-version2"/>
</workspaceFilter>

参见 / libs / foundation 的条目。

请确保您不要将此条目放在 filter.xml 中。这应该出现在 filter-vlt.xml

您的 filter.xml 条目将是这样的。

<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
    <filter root="/apps/myapp"/>
     <filter root="/etc/designs/myapp"/>
     <filter root="/etc/designs/bootstrap-custom-version2"/>     
</workspaceFilter>

/ libs / foundation 不存在于 filter.xml

然后浏览到{yourproject}\content\src\main\content\jcr_root并输入

vlt up --force

这会将 / apps / myapp ,即您的项目导入到您的文件系统中 / libs / foundation 但是当您构建项目时,libs / foundation将不会包含在构建中。

<强>结论:

filter-vlt.xml可帮助您将文件从CQ repo导入到编译项目所需的本地驱动器(文件系统)。但是当您在maven构建或安装到CQ存储库(文件系统到CQ repo)时,不包括这些文件。

仅将这些文件推送到其存储在filter.xml

中的CQ存储库中

答案 1 :(得分:2)

我明白了。我在Maven项目的内容部分导入了/ libs / foundation。 然后我在 maven-resources-plugin 配置

中添加了这个
<resource>  
      <directory>src/main/content/jcr_root</directory>  
      <includes>  
          <include>apps/**</include>  
          <include>libs/foundation/global.jsp</include>
    </includes>  
  </resource>  

此配置在编译过程中包含global.jsp,因此这有助于我所有包含global.jsp的Jsps成功编译。

但是也有必要在构建的其他方面排除libs,整个/ libs包含在构建中。

为此,我们必须在content / pom.xml中添加此条目

<build>
        <resources>
            <resource>
                <directory>src/main/content/jcr_root</directory>
                <filtering>false</filtering>
                <excludes>
                    <exclude>**/.vlt</exclude>
                    <exclude>**/.vltignore</exclude>
                    <exclude>libs/</exclude>
                </excludes>
            </resource>



        </resources>
相关问题