Alfresco 3.2c有一个跟踪图像,它被注入到使用Javascript的页脚,我需要删除一个项目。javascript实际上是硬编码在类org/alfresco/web/scripts/MessagesWebScript.java
的alfresco-share-src.zip
的SDK中。
我们目前正在使用Maven项目构建Alfresco,它从Maven插件和存储库中提取了大部分Alfresco和Share,给了我们一个干净的根构建添加。然而,由于这个类是硬编码的,我们不想触摸原始的jar/zip,我想我可以只是添加一个新的文件副本到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依赖项)。如果我尝试将依赖项添加到共享中。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>
我的分享。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脚本,但是您的解决方案是用这个类的分叉副本重新包装share WAR。
重新定义核心Alfresco(或Share)类是一个坏主意。这个web脚本是在webapp类路径下的Spring配置文件alfresco/slingshot-application-context.xml
中声明的,因此你应该做的是在alfresco/web-extension
下的*-context.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集成共享POM。
最后,我建议您将您的定制包作为AMP文件。Alfresco Maven SDK对此提供了完全的支持,你只需要将它声明为父节点——参见Google Docs的父节点POM示例。