global.jsp 在 CQ5 Archetype 中使用 JspC 时未在 Maven 项目中找到?

global.jsp not found in Maven project while using JspC in CQ5 Archtype?

我已经创建了 multi-module CQ5 Maven 项目。我的 Cq 版本是 5.5,Java 版本是 6.

这些是我遵循的步骤。

  1. 创建了 maven multi-module CQ maven 项目
  2. 在eclipse中导入它
  3. 使用 VLT 将现有项目从存储库导入 maven。
  4. 将项目转换为分面形式,因此 bundle 部分工作正常。
  5. content 模块中,我正在尝试使用 JspC 插件 我已在相应的 POM 文件中添加了正确的插件信息和依赖项。

问题是 当我编译 JspC 时说找不到 global.jsp

所以我也在我的项目中导入了 /libs 并确保这些库不包含在构建中。通过排除 /libs 文件夹。我提到了这个 link Adding /libs

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

我提到了这个 Link Autocomplete in JSP

我的目录结构

我的内容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>

我明白了。我在 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 都包含在构建中。

为此,我们必须在 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>

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

要导入 /lib/foundations,您需要在

下创建一个额外的文件过滤器-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 存储库导入到编译项目所需的本地驱动器(文件系统)。但是,当您进行 maven 构建或安装到 CQ 存储库(文件系统到 CQ 存储库)时,这些文件不包括在内。

只有条目出现在 filter.xml

中的那些文件才会被推送到 CQ 存储库中