0

Alfresco 3.2c 有一个跟踪图像,它使用我需要为项目删除的 Javascript 注入到页脚中。javascript 实际上是alfresco-share-src.zip在类中的 SDK 中硬编码的org/alfresco/web/scripts/MessagesWebScript.java

我们目前正在使用 Maven 项目构建 Alfresco,它从 maven 插件和存储库中提取了大部分 Alfresco 和 Share,为我们提供了干净的根构建添加。然而,由于这个类是硬编码的,我们不想触及原始的jars/zips,我想我可以将文件的新副本添加到share/src/main/java/org/alfresco/web/scripts/MessagesWebScript.java,将其编译到 war 文件的 WEB-INF 中,从而覆盖将从 jar 加载的内容(是的,我知道这样做的坏方法)。

但是,如果我只是添加文件,则会出现/share/src/main/java/org/alfresco/web/scripts/MessagesWebScript.java:[48,80] error: cannot find symbol错误

public class MessagesWebScript extends org.springframework.extensions.webscripts.MessagesWebScript

这让我相信它没有引入用于构建 war 文件的相同依赖项(即 spring-surf-parent 依赖项)。如果我尝试将该依赖项添加到 share.pom 文件(如下所示),maven 会成功构建,但依赖项会以某种方式拉入 servlet API jar 文件,将它们添加到战争中,然后我得到预期的The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory错误。

    <dependency>
            <groupId>org.springframework.extensions.surf</groupId>
            <artifactId>spring-surf-parent</artifactId>
            <version>1.2.0-M3</version>
    </dependency>

我的 share.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>
<artifactId>share</artifactId>
<name>Alfresco Share Client</name>
<packaging>war</packaging>
<description>Alfresco Share Client</description>
<parent>
    <groupId>nz.net.mycompany</groupId>
    <artifactId>custom-alfresco</artifactId>
    <version>1.0-SNAPSHOT</version>
</parent>


<dependencies>
    <dependency>
        <groupId>${alfresco.groupId}</groupId>
        <artifactId>share</artifactId>
        <type>war</type>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version><!--$NO-MVN-MAN-VER$-->
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.2.5</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.github.searls</groupId>
        <artifactId>jasmine-maven-plugin</artifactId>
        <version>1.3.1.2</version>
    </dependency>

</dependencies>
<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
        <resource>
            <directory>jetty</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <executable>${basedir}/src/scripts/less2css.sh</executable>
                <arguments>
                    <argument>${basedir}</argument>
                </arguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <excludes>
                    <!-- Integration Tests should not be run here -->
                    <exclude>**/IT*.java</exclude>
                </excludes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.14.1</version>
            <executions>
                <execution>
                    <goals>
<!--                             <goal>integration-test</goal> -->
<!--                             <goal>verify</goal> -->
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>com.github.searls</groupId>
            <artifactId>jasmine-maven-plugin</artifactId>
            <version>1.3.1.2</version>
            <executions>
                <execution>
                    <goals>
                        <goal>test</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <webDriverClassName>org.openqa.selenium.phantomjs.PhantomJSDriver</webDriverClassName>
                <webDriverCapabilities>
                    <phantomjs.binary.path>${project.basedir}/src/test/bin/phantomjs</phantomjs.binary.path>
                </webDriverCapabilities>
                <preloadSources>
                    <source>${project.basedir}/src/test/javascript/fixtures/fixture_messages.js</source>
                </preloadSources>
                <jsSrcDir>${project.basedir}/target/share/js/</jsSrcDir>
                <jsTestSrcDir>${project.basedir}/src/test/javascript/</jsTestSrcDir>
                <sourceIncludes>
                    <!-- add the ones we want first -->
                    <include>**/yui-common.js</include>
                    <include>**/alfresco.js</include>
                    <!-- Then the default -->
                    <include>**/*.js</include>
                </sourceIncludes>
                <haltOnFailure>false</haltOnFailure>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <!-- Here is can control the order of overlay of your (WAR, AMP, etc.) dependencies
                | NOTE: At least one WAR dependency must be uncompressed first
                | NOTE: In order to have a dependency effectively added to the WAR you need to
                | explicitly mention it in the overlay section.
                | NOTE: First-win resource strategy is used by the WAR plugin
                -->
                <overlays>
                    <!-- The current project customizations -->
                    <overlay />
                    <!-- The Share WAR -->
                    <overlay>
                        <groupId>${alfresco.groupId}</groupId>
                        <artifactId>share</artifactId>
                        <type>war</type>
                        <!-- To allow inclusion of META-INF -->
                        <excludes />
                    </overlay>
                </overlays>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>
4

1 回答 1

1

如果我理解正确,您想要覆盖单个 Java 类,在这种情况下,它恰好实现了一个 Web 脚本,但是您使用该类的分叉副本重新打包共享 WAR 的解决方案不起作用。

重新定义核心 Alfresco(或本例中的 Share)类是一个坏主意。这个 web 脚本是在 webapp 类路径的 Spring 配置文件中声明的alfresco/slingshot-application-context.xml,因此你应该做的是在你自己的*-context.xml文件中覆盖它alfresco/web-extension,例如

<?xml version='1.0' encoding='UTF-8'?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
   <!--  I18N resources and messages Web Script -->
   <bean id="webscript.org.springframework.extensions.messages.get" 
         parent="webscript" 
         class="my.custom.namespace.MessagesWebScript">
      <property name="webFrameworkConfigElement" ref="webframework.config.element"/>
      <property name="dependencyHandler" ref="dependency.handler"/>
   </bean>
</beans>

没有理由不应该从一开始就通过 Spring 实现覆盖。Spring bean 就是为此目的而设计的,它几乎不会增加工作量,同时让您能够更有效地调试,如果它不能按预期工作。

显然,您还需要确保您的自定义类my.custom.namespace.MessagesWebScript作为构建的一部分进行编译,听起来目前还没有这样做。这可能是因为您在 POM 中缺少一些 JAR(不是 WAR)依赖项 - 请查看我们使用的集合的Google Docs 集成共享 POM

最后,我建议您将自定义打包为AMP 文件Alfresco Maven SDK对此提供了全面支持,您只需将其声明为父级 - 请参阅Google Docs 父级 POM以获取示例。

于 2013-06-05T11:25:34.850 回答