How to pass Maven variable to asciidoctor-maven-plugin? - java

I have user-guide which uses AsciiDoc it is very beautiful despite that I did not spend much time for it.
AsciiDoc plugins are awesome. So I want to pass my Maven final name in the user guide.
Question: How to do that?
<finalName>${project.artifactId}-${project.version}-${version.state}-r${buildNumber}</finalName>
My asciidoctor-maven-plugin configurations are:
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>${asciidoctor.maven.plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj-pdf</artifactId>
<version>${asciidoctorj.pdf.version}</version>
</dependency>
<!-- Comment this section to use the default jruby artifact provided by the plugin -->
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby-complete</artifactId>
<version>${jruby.version}</version>
</dependency>
<!-- Comment this section to use the default AsciidoctorJ artifact provided by the plugin -->
<dependency>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj</artifactId>
<version>${asciidoctorj.version}</version>
</dependency>
</dependencies>
<configuration>
<sourceDirectory>src/docs/asciidoc</sourceDirectory>
<sourceDocumentName>manual.adoc</sourceDocumentName>
<!-- Attributes common to all output formats -->
<attributes>
<sourcedir>${project.build.sourceDirectory}</sourcedir>
</attributes>
</configuration>
<executions>
<execution>
<id>generate-pdf-doc</id>
<phase>generate-resources</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>pdf</backend>
<!-- Since 1.5.0-alpha.9 PDF back-end can use 'rouge' as well as 'coderay'
source highlighting -->
<sourceHighlighter>rouge</sourceHighlighter>
<attributes>
<icons>font</icons>
<pagenums/>
<toc/>
<idprefix/>
<idseparator>-</idseparator>
</attributes>
</configuration>
</execution>
</executions>
</plugin>

The official user guide cover this case in its Passing POM properties section:
It is possible to pass properties defined in the POM to the Asciidoctor processor. This is handy for example to include in the generated document the POM artifact version number.
This is done by creating a custom AsciiDoc property in the attributes section of the configuration. The AsciiDoc property value is defined in the usual Maven way: ${myMavenProperty}.
<attributes>
<project-version>${project.version}</project-version>
</attributes>
The custom AsciiDoc property can then be used in the document like this:
The latest version of the project is {project-version}.
Accordingly, you can hence apply the following to your existing configuration:
<configuration>
<sourceDirectory>src/docs/asciidoc</sourceDirectory>
<sourceDocumentName>manual.adoc</sourceDocumentName>
<!-- Attributes common to all output formats -->
<attributes>
<sourcedir>${project.build.sourceDirectory}</sourcedir>
<!-- the new property -->
<final-name>${project.build.finalName}</final-name>
</attributes>
</configuration>

Related

Query DSL & Maven: Classes not generated, but only on command line (in eclipse it is working fine)

We are using a setup with Spring Boot, Hibernate, Query DSL and Maven with Java 1.8
Recently, I've added Query DSL to the project with the configuration listed below. To make it work, I had to configure the Java Compiler in the eclipse project settings to allow Annotation Processing and also add the Query DSL .jar file to the eclipse Annotation Factory Path.
This setup worked as expected. It generated the custom Q classes and I could use them in my code. When now running the mvn clean install on the command line, every class in my code throws the error cannot find symbol, because the class is missing. Is there anything else I need to configure - similar to the .jar file in the eclipse settings - to make the build process work?
EDIT: This question is not a duplicate of this question because I did not ask why this error (cannot find a symbol) occurs but rather how to configure QueryDSL to also work on the command line.
EDIT2: I have now tried to integrate the build-helper-maven-plugin to use multiple source paths as an input. This did not help either. I also tried to generate the files into a src folder. It did not help either.
When I first compile the library in eclipse, the mvn compile goes through on the command line, but mvn clean compile still fails, because it just uses the compiled files of eclipse again. The apt-maven-plugin is executed, which can be seen just before the build process fails:
[INFO] --- apt-maven-plugin:1.1.3:process (default) # project1 ---
[INFO]
[INFO] --- build-helper-maven-plugin:1.9.1:add-source (add-source) # project1 ---
[INFO] Source directory: C:\Users\user1\git\project1\src\main\generated added.
[INFO]
[INFO] --- maven-processor-plugin:2.2.4:process (process) # project1 ---
[ERROR] diagnostic: [...]
EDIT3: When I remove every import statement which is referring to the Q classes, the build process goes through (obviously). It is, however, remarkable, that the Q classes get compiled correctly in that case. They appear in the target folder as .class files as they should. Could it be, that the Q classes are compiled too late?
Here is an excerpt of the pom.xml
<?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>
[...]
<prerequisites>
<maven>3.0.0</maven>
</prerequisites>
<dependencies>
[...]
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>4.1.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>4.1.3</version>
</dependency>
</dependencies>
<build>
<defaultGoal>spring-boot:run</defaultGoal>
<plugins>
[...]
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
[...]
</build>
</project>
This is the configuration of the eclipse project settings:
This is the error message which is displayed in the console:
[INFO] --- maven-processor-plugin:2.2.4:process (process) # project1 ---
[ERROR] diagnostic: C:\Users\user1\git\project1\src\main\java\com\project1\repository\UserRepositoryImpl.java:3: error: cannot find symbol
import static com.project1.domain.QUser.user;
^
symbol: class QUser
location: package com.project1.domain
[ERROR] diagnostic: C:\Users\user1\git\project1\src\main\java\com\project1\repository\UserRepositoryImpl.java:3: error: static import only from classes and interfaces
import static com.project.domain.QUser.user;
^
This is old question but this is how i find my solution, added classifier for jpa dependency:
<!-- BEGIN: 'querydsl-jpa' -->
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>${querydsl-jpa.version}</version>
<classifier>apt</classifier>
</dependency>
<!-- END: 'querydsl-jpa' -->
My complete pom:
<!-- BEGIN: BUILD -->
<build>
<!-- BEGIN: PLUGINS -->
<plugins>
<!-- BEGIN: apt-maven-plugin -->
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>${apt.version}</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/apt</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
<!-- END: apt-maven-plugin -->
</plugins>
<!-- END: PLUGINS -->
</build>
<!-- END: BUILD -->
<!-- BEGIN: DEPENDENCIES -->
<dependencies>
<!-- *********************************************** -->
<!-- BEGIN: 'QUERYDSL DEPENDENCIES' -->
<!-- BEGIN: 'querydsl-apt' -->
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${querydsl-apt.version}</version>
</dependency>
<!-- END: 'querydsl-apt' -->
<!-- BEGIN: 'querydsl-jpa' -->
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>${querydsl-jpa.version}</version>
<classifier>apt</classifier>
</dependency>
<!-- END: 'querydsl-jpa' -->
<!-- *********************************************** -->
<!-- END: 'QUERYDSL DEPENDENCIES' -->
</dependencies>
For me, it didn't work because it conflicted with maven-compiler-plugin with already set annotation processor. Just deleted the use of apt-maven-plugin and added its annotation processor in maven-compiler-plugin.
<build>
<plugins>
<!-- related to issues:-->
<!-- - https://github.com/querydsl/querydsl/issues/2654 -->
<!-- - https://github.com/querydsl/querydsl/issues/2242 -->
<!-- Using apt-maven-plugin conflicts with other annotation processors (like mapStruct) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
<path>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>5.0.0</version>
<classifier>jpa</classifier>
</path>
<path>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>2.2.3</version>
</path>
<path>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</path>
<!-- other annotation processors -->
</annotationProcessorPaths>
</configuration>
</plugin>
<!-- <plugin>-->
<!-- <groupId>com.mysema.maven</groupId>-->
<!-- <artifactId>apt-maven-plugin</artifactId>-->
<!-- <version>1.1.3</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <goals>-->
<!-- <goal>process</goal>-->
<!-- </goals>-->
<!-- <configuration>-->
<!-- <outputDirectory>target/generated-sources</outputDirectory>-->
<!-- <processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>-->
<!-- </configuration>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
</plugins>
</build>
But there is an issue with using querydsl annotation processor in maven-compiler-plugin. You have to add jakarta.persistence-api and javax.annotation-api.
I would rather use profile to generate these Qclasses only when db change occurs.
cons:
-your diff in pull requests is clean when you don't change db schema because for each generation these files tend to generate differently for some reason (atleast in my case).
-you can manage witch of tables present in your db will have Qclasses (sometimes it is a pain when you forget to regenerate them after changing db schema)
-well not that it is lots of time . but builds are faster if You don't change schema and profile is turned off.
Try something like this and turn on profile when You want to generate changed schema Qclasses :
<properties>
<whitelisted.tables>
user_accunt,
other
</whitelisted.tables>
</properties>
<profiles>
<profile>
<id>generate</id>
<build>
<plugins>
<plugin>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-maven-plugin</artifactId>
<version>${querydsl.version}</version>
<executions>
<execution>
<goals>
<goal>export</goal>
</goals>
</execution>
</executions>
<configuration>
<jdbcDriver>org.postgresql.Driver</jdbcDriver>
<jdbcUrl>jdbc:postgresql://localhost:port/dbname</jdbcUrl>
<packageName>your.package.name.for.q</packageName>
<jdbcUser>dbusername</jdbcUser>
<jdbcPassword>dbpassword</jdbcPassword>
<targetFolder>${project.basedir}/src/main/java/</targetFolder>
<spatial>true</spatial>
<tableNamePattern>${whitelisted.tables}</tableNamePattern>
</configuration>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.1.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
</profiles>
The generated-source directory are not automatically included in the jar.
You need to use the Maven build helper plugin to fix this issue, for example:
https://github.com/alexec/javahelp-skeleton/blob/master/pom.xml
You can try out few things:
1.try to put <clearOutputDir>false</clearOutputDir> in your configuration tag
2. Sometimes classes might not be getting generated before the compile phase. So try to put phase in your plugin
<execution>
<phase>generate-sources</phase>
<goals>
<goal>...</goal>
</goals>
</execution>
By convention Maven assumes all source code is in 'src/main/java', compiles this and put all *.class file in target.
So if you have a class 'Alien.java' in <project-root>/alice/in/wonderland, your won't be able to access it (in src/main/java) because maven puts everything from src/main/java in classpath for your compiler and hence compiler is unaware of any source code (*.java) anywhere else.
In your case you are generating your source code in directory target/generated-sources/java, so you will have to tell maven about it. As mentioned in some other answers you may use build-helper-plugin for this, let maven know that your source resides on target/generated-sources/java by
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/java</source>
<source>alice/in/wonderland</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Edit: You have mentioned wrong path in build-helper-plugin
I see although you are using build helper plugin but you are using wrong path
--- build-helper-maven-plugin:1.9.1:add-source (add-source) # project1 ---
[INFO] Source directory: C:\Users\user1\git\project1\src\main\generated added.
Instead of src\main\generated you should use <source>target/generated-sources/java</source>

How do I include tools.jar in my dependencies?

This reference explained how to include tools.jar in the dependencies.
But I don't know where should I insert that code to?
Should I insert it to the setting.xml of Maven or the pom.xml of my Java project?
I used the default maven in Eclipse 4.5.2(Mars.2 Release in Win7).
I want to include tools.jar in my project.
I could use the following code to include it in the pom.xml.
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<scope>system</scope>
<version>1.4.2</version>
<systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
</dependency>
I also want to try to use java.home, not JAVA_HOME.
I only know that they are different, but I don't exactly know the differences between them.
After reading that reference, I want to try it out. But I failed.
So how should I use java.home to configure the pom.xml file to include tools.jar?
UPDATE:
I could reference java.home like this:
<project ...>
...
<properties>
<java.home>D:\Program Files\Java\jdk1.6.0_45</java.home>
</properties>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.4.2</version>
<scope>system</scope>
<systemPath>${java.home}/lib/tools.jar</systemPath>
</dependency>
</dependencies>
</project>
You can define a similar profile in your pom.xml as -
<!--This can help you use a custom java home path-->
<properties>
<java.home>/your/path/to/java</java.home>
</properties>
...
<profiles>
<profile>
<id>default-tools.jar</id>
<activation>
<property>
<name>java.vendor</name>
<value>Sun Microsystems Inc.</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.4.2</version>
<scope>system</scope>
<systemPath>${java.home}/relative/path/to/lib/tools.jar</systemPath>
</dependency>
</dependencies>
</profile>
Using the reference mentioned to form the profile above.
You need to specify the path to your custom Java home under the properties which can further replace it in the systemPath under the dependency where you specify further the relative path to the tools.jar.
#nullpointer is correct, just to add on the maven properties regarding your java home, you can see the output of the Maven java.home property as compared to your JAVA_HOME environment variable with running mvn validate and adding to your pom the code snippet below:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>Displaying value of java home property: ${java.home}</echo>
<echo>Displaying value of JAVA_HOME variable: ${env.JAVA_HOME}</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
For example, on my system it outputs (among other things):
[echo] Displaying value of java home property: /usr/lib/jvm/java-8-openjdk-amd64/jre
[echo] Displaying value of JAVA_HOME variable: /usr/lib/jvm/java-8-openjdk-amd64

Eclipse tycho updating version to svn revision

i want to update the minor version number of
product, all feature and all modules to its coresponding svn revision number (later only mentioned as buildNumber).
this shall work automatically, so no modification on .product, feature.xml, MANIFEST.MF nor pom.xml are needed
My RCP Applicatin has the following structure (names simplified)
parent
feature-core
feature-addons(4)
modules(loads)
product
i tried to include buildnumber-maven-plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>true</doCheck>
<doUpdate>true</doUpdate>
<providerImplementations>
<svn>javasvn</svn>
</providerImplementations>
</configuration>
<dependencies>
<dependency>
<groupId>com.google.code.maven-scm-provider-svnjava</groupId>
<artifactId>maven-scm-provider-svnjava</artifactId>
<!-- version>2.1.1</version -->
<!-- latest is 2.1.1 -->
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.tmatesoft.svnkit</groupId>
<artifactId>svnkit</artifactId>
<!-- version>1.8.11</version -->
<!-- latest is 1.8.11 -->
<version>1.7.8</version>
</dependency>
</dependencies>
</plugin>
and
<finalName>${project.artifactId}-${project.version}-r${buildNumber}</finalName>
but this only creates a zip file with the buildNumber and leaves the version untouched.
p2 update manager requires the version to change (a simple SNAPSHOT build does not work for my product)
so by now the version number is eg. 1.0.0 and should be automatically updated to 1.0.${buildNumber}
its ok, if this is not possible in the parent pom and needs to be done in each feature or modules pom
there is a feature in Tycho that updates the version qualifier (4th digit) to the timestamp of the latest git commit:
https://wiki.eclipse.org/Tycho/Reproducible_Version_Qualifiers
https://git.eclipse.org/c/tycho/org.eclipse.tycho.extras.git/tree/tycho-buildtimestamp-jgit/src/main/java/org/eclipse/tycho/extras/buildtimestamp/jgit/JGitBuildTimestampProvider.java
you would have to develop a similar BuildTimeStampProvider plexus component for SVN.

Why does jaxb log "No XmlSchema annotation found for <my package name>" when getting an instance of JAXBContext?

I have an xsd file that, when compiled using the jaxb-2 maven plugin, generates java source.
The header for my xsd is:
<schema targetNamespace="example.company.com"
elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:prefix="example.company.com">
Whenever I attempt to get the JAXBContext for use in marshaling/unmarshaling using this code:
JAXBContext jc = JAXBContext.newInstance("com.company.example", com.company.example.ObjectFactory.class.getClassLoader());
I get hundreds of error messages in my console that look like this:
No XmlSchema annotation found for com.company.example
After all of those error messages, the marshaling works. I would like to get rid of the errors though.
The jaxb2 maven plugin is defined in my pom like so:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.3.1</version>
<dependencies>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>2.1.13</version>
</dependency>
<dependency>
<groupId>net.sourceforge.ccxjc</groupId>
<artifactId>cc-xjc-plugin</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<arguments>-enableIntrospection -verbose</arguments>
<schemaDirectory>${basedir}/src/main/xsd</schemaDirectory>
<outputDirectory>${basedir}/src/main/java</outputDirectory>
<packageName>com.company.example</packageName>
<verbose>true</verbose>
<failOnNoSchemas>true</failOnNoSchemas>
<clearOutputDir>false</clearOutputDir>
<arguments>-copy-constructor</arguments>
<extension>true</extension>
</configuration>
</plugin>
It looks as though the package-info.java (that contains the #XmlSchema annotation) file that was generated along with the other model files from the XML Schema is not being compiled.
Update
I am running OSGi and using Java SE
You should make sure you import the javax.xml.bind package in your manifest. Their can be ClassLoader issues with javax classes in OSGi environments.
You didn't map your package to the namespace "http://www.w3.org/2001/XMLSchema". To do this, make your header like this:
<schema
xmlns=...
xmlns:po=....
targetNamespace="http://www.w3.org/2001/XMLSchema"
>
Also, add this annotation to your class:
#javax.xml.bind.annotation.XmlSchema (namespace = "http://www.w3.org/2001/XMLSchema")
For more information about XmlSchema, see these docs: http://docs.oracle.com/javase/7/docs/api/javax/xml/bind/annotation/XmlSchema.html

Removing the remote tracking image from Alfresco within a Maven project

Alfresco 3.2c has a tracking image that's injected into the page footer using Javascript that I need to remove for a project. The javascript is actually hard coded in the SDK in the alfresco-share-src.zip in the class org/alfresco/web/scripts/MessagesWebScript.java.
We're currently building Alfresco using a Maven project and it pulls most of Alfresco and Share from maven plugins and repositories, giving us a clean root build additions in. However since this class is hard coded and we don't want to touch the original jars/zips, I thought I could just add a new copy of the file to share/src/main/java/org/alfresco/web/scripts/MessagesWebScript.java, compiling it into the war file's WEB-INF and thereby overriding what would get loaded from the jar (yes, I know a bad way of doing it).
However, if I just add the file, I get the error /share/src/main/java/org/alfresco/web/scripts/MessagesWebScript.java:[48,80] error: cannot find symbol on the line
public class MessagesWebScript extends org.springframework.extensions.webscripts.MessagesWebScript
Which leads me to believe it's not pulling in the same dependencies used to build the war file (namely the spring-surf-parent dependency). If I try to add that dependency to the share.pom file (shown below), maven successfully builds, but the dependency somehow pulls in the servlet API jar files, adds them to the war and then I get the expected The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory errors.
<dependency>
<groupId>org.springframework.extensions.surf</groupId>
<artifactId>spring-surf-parent</artifactId>
<version>1.2.0-M3</version>
</dependency>
My share.pom looks like the following:
<?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>
If I understand correctly, you want to override a single Java class, which in this case, happens to implement a web script, but your solution of repackaging the share WAR with a forked copy of this class is not working.
Re-defining core Alfresco (or Share in this case) classes is a bad idea. This web script is declared in the Spring config file alfresco/slingshot-application-context.xml in the webapp classpath, and therefore what you should be doing is overriding it in your own *-context.xml file under alfresco/web-extension, e.g.
<?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>
There is no reason why you should not implement the override through Spring from the start. Spring beans are designed for this purpose and it adds very little to the effort while giving you the ability to more effectively debug if it does not work as you expect.
Obviously you will also need to make sure that your custom class my.custom.namespace.MessagesWebScript compiles as part of your build, and it sounds like it is not doing so at present. This is probably because you are missing some JAR (not WAR) dependencies in your POM - take a look at the Google Docs integration Share POM for the set which we use.
Lastly I would suggest that your package your customisation as an AMP file. The Alfresco Maven SDK provides full support for this and you just need to declare it as a parent - see the Google Docs parent POM for an example.

Categories