java - 从 Maven 项目中的 Alfresco 中删除远程跟踪图像

标签 java maven alfresco alfresco-share maven-war-plugin

Alfresco 3.2c 有一个跟踪图像,它使用 Javascript 注入(inject)到页脚中,我需要为项目删除该图像。 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 文件,将它们添加到 war 中,然后我得到预期的 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>

最佳答案

如果我理解正确的话,您想要覆盖单个 Java 类,在本例中,该类恰好实现了一个 Web 脚本,但是您使用此类的 fork 副本重新打包共享 WAR 的解决方案不起作用。

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

<?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 integration Share POM对于我们使用的集合。

最后,我建议您将自定义打包为 AMP fileAlfresco Maven SDK对此提供全面支持,您只需将其声明为父级 - 请参阅 Google Docs parent POM举个例子。

关于java - 从 Maven 项目中的 Alfresco 中删除远程跟踪图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16928525/

相关文章:

单独 JAR 文件中的 JavaBeans 类

java - 是否可以使用 SWIG 生成的 JNI 从 C 代码调用 java 方法?

java - 在 Intellij Idea 中查找 com.fasterxml.jackson.core 的问题

java - 如何在将 jar 安装到 m2 存储库时下载 jar 依赖项

Java、Alfresco Web 服务 API 和 Unicode NamedValues

java - 更改 AlfrescoDocument 属性没有任何效果

java - 具有 CRUD 静态方法的观察者模式和 DAO 类

java - 我可以使用 java.awt.FileDialog 只允许用户选择文件夹吗

maven - 将 Enunciate 与 Maven/多个模块一起使用

java - 使内容节点成为节点的主要父节点