In my Maven build, I use the antrun plugin to invoke an ant task.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<tasks>
<property name="plugin_classpath" refid="maven.plugin.classpath" />
<java classname="org.apache.tools.ant.launch.Launcher"
fork="true" failonerror="true">
<classpath>
<pathelement path="${plugin_classpath}" />
</classpath>
</java>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<!-- DEPENDENCIES FROM PROJECT DUPLICATED HERE -->
</dependencies>
</plugin>
I need to duplicate all the project dependencies in the section indicated, so that they are available to the ant task. Is there a way to avoid this duplication, by referring to the project's dependencies instead of copy-pasting them?
Here's how you can do it:
<property name="plugin_classpath" refid="maven.plugin.classpath" />
<property name="compile_classpath" refid="maven.compile.classpath" />
<java classname="org.apache.tools.ant.launch.Launcher"
fork="true" failonerror="true">
<classpath>
<pathelement path="${plugin_classpath}" />
<pathelement path="${compile_classpath}" />
</classpath>
</java>
Reference:
Maven Antrun Plugin > Referencing the Maven Classpaths
Related
If Frege had a POM and was uploaded to maven central or bintray, I could easily use it as a maven dependency in maven, gradle, buildr, and via grapes.
I couldn't find it, though. Is there any such thing?
I would not require a full maven plugin.
There is a Maven plugin for Frege here: https://github.com/talios/frege-maven-plugin but I am not sure how much it is up to date with current Frege version.
Further as far as I know, the Frege jar is still not in any central repository so you would need to have it in some local repository to use that plugin. For example, https://github.com/talios/frege-testing/blob/master/pom.xml
You can also invoke the Frege compiler through Ant in Maven (not the best way but still an option):
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<target>
<property name="compile_classpath" refid="maven.compile.classpath" />
<property name="outputDir"
value="${project.build.outputDirectory}" />
<property name="sourceDir" value="src/main/frege" />
<property name="fregec" value="${frege:frege:jar}" />
<exec executable="java" failonerror="true">
<arg value="-Xss1m" />
<arg value="-Dfrege.javac=javac" />
<arg value="-classpath" />
<arg value="${compile_classpath}" />
<arg value="frege.compiler.Main" />
<arg value="-d" />
<arg path="${outputDir}" />
<arg value="${sourceDir}/helloworld/Foo.fr" />
<arg value="${sourceDir}/helloworld/bar.fr" />
</exec>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Here also frege:frege:jar refers to the Frege jar in local repository. If you have any Java dependency from your Frege code or other way around, it is better to have those as separate modules (a Java module and a Frege module) so that the compilation order (Java and Frege compilation) is determined by the order the modules are built.
I am trying to create a P2 repository using Tycho for a plugin that extends the Eclipse environment. When I try to do a mvn install, the zip file it creates adds the plugins from org.eclipse which I do not want included.
I have already defined the plugin not to include dependencies (even though the default was already false)
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-repository-plugin</artifactId>
<configuration>
<includeAllDependencies>false</includeAllDependencies>
</configuration>
</plugin>
At the moment it creates a zip file of at least 48MB.
The p2 repository built by the eclipse-repository packaging type only contains (transitive) inclusions of the module's category.xml and *.product files. "Transitive inclusion" is everything listed in these files, and everything included in the included features. By default, artifacts that are only referenced (e.g. in the bundle manifests) are not included.
So if the p2 repository contains too many artifacts, simply don't include the artifacts, or the features containing the artifacts.
In case you want to build an RCP that has to include certain things that should not go into the p2 repository, move the product definition into a separate eclipse-repository module.
Try this
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>prepare-feature-distribution</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<mkdir
dir="${basedir}/target/${project.parent.artifactId}/${feature.version}" />
<!-- Copy core and targetPlatform jars -->
<copy
todir="${basedir}/target/${project.parent.artifactId}/${feature.version}">
<fileset dir="${basedir}/target/repository/plugins">
<exclude name="ch.qos.logback.slf4j*.jar" />
<exclude name="javax.xml.bind*.jar" />
<exclude name="org.apache.xerces*.jar" />
<exclude name="org.apache.xml.resolver*.jar" />
<exclude name="org.apache.xml.serializer*.jar" />
<exclude name="org.eclipse.equinox.common*.jar" />
<exclude name="org.eclipse.equinox.ds*.jar" />
<exclude name="org.eclipse.equinox.launcher.win32.win32.x86*.jar" />
<exclude name="org.eclipse.equinox.launcher*.jar" />
<exclude name="org.eclipse.equinox.util*.jar" />
<exclude name="org.eclipse.net4j.jms.api*.jar" />
<exclude name="org.eclipse.osgi.services*.jar" />
<exclude name="org.eclipse.osgi*.jar" />
</fileset>
</copy>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
I'd like to be able to filter filenames as well as file contents in Maven.
The below snippet enables filtering on file contents, but I need to be able to rename files too.
The usage scenario is that I'd like all static resources in my webapp to be numbered, so they can be treated as different versions by Amazon's CloudFront. Naturally managing the numbers manually would be impractical, so I'd like the build process to do this.
For instance a file called
logo_VERSION.jpg
would end up being called
logo_254.jpg
Any ideas if this is possible without writing a custom plugin?
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>/src/main/webapp</directory>
<filtering>true</filtering>
</resource>
</webResources>
...
I've done something similar using the antrun plugin - sometimes you just have to drop back into ant.
pom snippet
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>build</id>
<phase>prepare-package</phase>
<configuration>
<tasks>
<property name="project.version" value="${project.version}"/>
<property name="all.environs" value="DEV1,DEV2,DEV3,DEV4,UAT,PROD"/>
<property name="application.environments"
value="${application.environments}" />
<ant antfile="${basedir}/build.xml" target="setup" />
<ant antfile="${basedir}/build.xml" target="build"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
build.xml
<property name="ant-contrib-jar" value="${user.home}/.ant/lib/ant-contrib-1.0b3.jar"/>
<target name="setup" unless="ant-contrib.present">
<echo>Getting ant-contrib</echo>
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${ant-contrib-jar}"
src="http://nexus.inhouse.com:8081/nexus/content/repositories/central/ant-contrib/ant-contrib/1.0b3/ant-contrib-1.0b3.jar"/>
</target>
<target name="taskdefs">
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${ant-contrib-jar}"/>
</classpath>
</taskdef>
</target>
<target name="build" depends="taskdefs">
<echo message="basedir: ${basedir}"/>
<echo message="project.version: ${project.version}"/>
<foreach list="${application.environments}" target="jar-resources" param="app.env" trim="true">
<param name="basedir" value="${basedir}" />
<param name="project.version" value="${project.version}" />
</foreach>
</target>
<target name="jar-resources">
<mkdir dir="${basedir}/target/${app.env}"/>
<copy todir="${basedir}/target/${app.env}">
<fileset dir="${basedir}/src/main/resources">
<include name="mail_config.properties"/>
<include name="service.properties"/>
</fileset>
</copy>
<filterset id="applicationFilterSet">
<filtersfile file="${basedir}/src/main/filters/filter-${app.env}.properties"/>
<filter token="PROJECT.VERSION" value="${project.version}"/>
</filterset>
<copy file="${basedir}/src/main/resources/coresystem.properties"
tofile="${basedir}/target/${app.env}/coresystem.properties.${app.env}">
<filterset refid="applicationFilterSet"/>
</copy>
<copy file="${basedir}/src/main/resources/extraProps.properties"
tofile="${basedir}/target/${app.env}/extraProps_${app.env}.properties">
<filterset refid="applicationFilterSet"/>
</copy>
<jar destfile="${basedir}/target/MyApp-env-${project.version}-${app.env}.jar"
basedir="${basedir}/target/${app.env}" />
</target>
We are in the middle of a large Java EE project/programme. Up to this point, we've been using Eclipse and Maven for our development. The appserver we are targeting is WebLogic (Oracle, these days).
It has been decided we are going to start using Oracle Business Rules (Part of Oracle SOA Suite 11g). Development for Soa Suite is confined to JDeveloper. It has some nice ant scripts to build and deploy SOA Composites (which is how rules are packaged and deployed).
I have been tasked with getting these ant scripts to run from maven using antrun, and I've gotten some of the way, but not all...
My main question is: has anyone succeeded doing this? (Has anyone even attempted..? Can't really find anything googling...)
Below is the relevant part of my pom:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<target>
<property name="oracle.home" value="C:\Oracle\Middleware\jdeveloper"/>
<property name="oracle.soa.mgmt.home" value="C:\Oracle\Middleware\jdeveloper"/>
<property name="common.components.home" value="C:\Oracle\Middleware\oracle_common"/>
<property name="env.JAVA_HOME" value="${java.home}"/>
<property name="env.PWD" value="."/>
<ant antfile="${oracle.home}\bin\ant-sca-compile.xml"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Maven is run from the project dir, outside the Oracle/Middleware tree. This almost works...
Actually, it gives the following result:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building BilagorReglerSCA
[INFO] task-segment: [compile]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [antrun:run {execution: default}]
[INFO] Executing tasks
main:
scac:
Validating composite "C:\JDeveloper\mywork\BilagorReglerSCA\BilagorRegler\composite.xml"
[scac] oracle.fabric.common.wsdl.XSDException: Error loading schema from file:/C:/JDeveloper/mywork/BilagorReglerSCA/BilagorRegler/BilagorRegler_DecisionService.wsdl [Cause=Error in getting XML input stream: oramds:/soa/shared/rules/BpelProcess.xsd: oracle.mds.exception.MDSException: MDS-00054: Filen som ska laddas oramds:/soa/shared/rules/BpelProcess.xsd finns inte.]
[scac] at oracle.fabric.common.wsdl.SchemaBuilder.loadEmbeddedSchemas(SchemaBuilder.java:496)
[scac] at oracle.fabric.common.wsdl.SchemaBuilder.loadSchemasFromWSDL(SchemaBuilder.java:365)
...
The phrase "Filen som ska laddas oramds:/soa/shared/rules/BpelProcess.xsd finns inte." means the "file you are trying to load does not exist" (why does my client insist on installing Swedish language version of Windows, rather than international?).
ant-sca-compile.xml contains numerous import statements similar to this:
<fileset dir="${common.components.home}/modules">
...
<include name="oracle.mds_11.1.1/oramds.jar"/>
I assume oramds.jar is needed to process oramds-URL:s, which are used in the WSDS/XSD:s JDeveloper generates.
Any help appreciated...
OK, so I eventually got a chance to sit down with an ace Oracle consultant and get this to work.
This is what we came up with:
<properties>
<oracle.fmw.soa.home>C:/Oracle/Middleware</oracle.fmw.soa.home>
<!-- this is relative reference to JDK / Jrockit from ant-sca-compile|*.xml. For jdev it is ../../, for Soa Suite: TBD. -->
<env.JAVA_HOME>../../jdk160_24</env.JAVA_HOME>
<!-- For real server with Soa Suite installed use: Oracle_SOA1, for devenv use jdeveloper -->
<oracle.fmw.productName>jdeveloper</oracle.fmw.productName>
<antOutputDir>deploy</antOutputDir>
<mvnOutputDir>target</mvnOutputDir>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sca-compile</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<property name="scac.input" value="${basedir}/composite.xml" />
<property name="scac.application.home" value="${basedir}/.." />
<property name="oracle.home" value="${oracle.fmw.soa.home}/${oracle.fmw.productName}" />
<ant
antfile="${oracle.fmw.soa.home}/${oracle.fmw.productName}/bin/ant-sca-compile.xml"
dir="${oracle.fmw.soa.home}/${oracle.fmw.productName}/bin/"
target="scac" />
</target>
</configuration>
</execution>
<execution>
<id>sca-package</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target name="package">
<property name="build.compiler" value="extJavac" />
<property name="compositeName" value="${project.artifactId}" />
<property name="compositeDir" value="${basedir}" />
<property name="revision" value="${project.version}" />
<property name="scac.application.home" value="${basedir}/.." />
<property name="oracle.home" value="${oracle.fmw.soa.home}/${oracle.fmw.productName}" />
<property name="antOutputFile" value="sca_${project.artifactId}_rev${project.version}.jar" />
<property name="mvnOutputFile" value="${project.artifactId}-${project.version}.jar" />
<ant
antfile="${oracle.fmw.soa.home}/${oracle.fmw.productName}/bin/ant-sca-package.xml"
dir="${oracle.fmw.soa.home}/${oracle.fmw.productName}/bin"
target="package" />
<copy tofile="${mvnOutputDir}/${mvnOutputFile}" file="${antOutputDir}/${antOutputFile}" />
</target>
</configuration>
</execution>
<execution>
<id>sca-deploy</id>
<phase>deploy</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target name="deploy">
<property name="serverURL" value="${weblogic.serverURL}" />
<property name="user" value="${weblogic.user}" />
<property name="password" value="${weblogic.password}" />
<property name="sarLocation" value="${basedir}/deploy/sca_${project.artifactId}_rev${project.version}.jar" />
<property name="overwrite" value="true" />
<property name="forceDefault" value="true" />
<property name="partition" value="default" />
<property name="oracle.home" value="${oracle.fmw.soa.home}/${oracle.fmw.productName}" />
<ant
antfile="${oracle.fmw.soa.home}/${oracle.fmw.productName}/bin/ant-sca-deploy.xml"
dir="${oracle.fmw.soa.home}/${oracle.fmw.productName}/bin"
target="deploy" />
</target>
</configuration>
</execution>
<execution>
<id>sca-test</id>
<phase>deploy</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<property name="jndi.properties.input" value="${basedir}/sca-test.jndi.properties" />
<property name="scatest.input" value="scatestinput" />
<property name="scatest.format" value="junit" />
<property name="scatest.result" value="reports" />
<property name="oracle.home" value="${oracle.fmw.soa.home}/${oracle.fmw.productName}" />
<ant
antfile="${oracle.fmw.soa.home}/${oracle.fmw.productName}/bin/ant-sca-test.xml"
dir="${oracle.fmw.soa.home}/${oracle.fmw.productName}/bin"
target="test" />
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Note, both different sets of properties and parameters to the ant-tag than what I was originally attempting with.
To run on a CI-server, you obviously need a local install of JDeveloper or SOA Suite. weblogic.serverURL, weblogic.user and weblogic.password needs to be set to your corresponding environment (I use profiles for local/dev/tst/etc...).
Other than that, it works like a charm...
I've not used Maven + Oracle SOA build scripts but generally when using any of the Oracle deployment tools (ADF, SOA, etc) you will need to have either an Oracle SOA Home or a JDev home (with the SCA extension) on the same machine that the build is running on. You'll need to set the Ant environment variables correctly e.g. oracle.home and common.components.home etc
Use ant-sca-package.xml (not ant-sca-compile.xml):
<ant antfile="ant-sca-package.xml" dir="${env.BEA_HOME}/jdeveloper/bin">
<property name="compositeDir" value="#{compositeDir}" />
<property name="compositeName" value="#{compositeName}" />
<property name="revision" value="${deploy.revision}" />
</ant>
Did I understand right from this page that Cargo Maven plugin doesn't support hot remote deployment to GlassFish 3.x? If I'm wrong, how can I configure it to support such type of operation?
Maybe I should use some other plugin? I'd like to deploy to GlassFish remote installation, through HTTP, in "hot" mode.
This is what I've done so far:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<tasks>
<tempfile property="ant.temp-ear" deleteonexit="true" destdir="/tmp" />
<copy
file="${project.build.directory}/${project.build.finalName}.${project.packaging}"
tofile="${ant.temp-ear}" verbose="true" />
<exec executable="${glassfish.home}/glassfish/bin/asadmin"
failonerror="true">
<arg value="--user=${glassfish.username}"/>
<arg value="--passwordfile=${glassfish.passwordfile}"/>
<arg value="--interactive=false"/>
<arg value="--host=${glassfish.host}"/>
<arg value="--port=${glassfish.adminport}"/>
<arg value="deploy"/>
<arg value="--force"/>
<arg value="--name=${project.artifactId}"/>
<arg value="${ant.temp-ear}"/>
</exec>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Works perfectly, but asadmin (and the entire GlassFish, I assume) has to be installed on the same machine where mvn is executed.
Is it possible to perform the same task with Cargo plugin?
Does this answer your question?
<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<container>
<containerId>glassfish3x</containerId>
<type>remote</type>
</container>
<configuration>
<type>runtime</type>
<properties>
<cargo.hostname>dev-server-01</cargo.hostname>
<cargo.servlet.port>8080</cargo.servlet.port>
<cargo.remote.username>user</cargo.remote.username>
<cargo.remote.password>pass</cargo.remote.password>
<cargo.glassfish.domain.name>domain-name</cargo.glassfish.domain.name>
<cargo.glassfish.adminPort>4848</cargo.glassfish.adminPort>
</properties>
</configuration>
<deployables>
<deployable>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<type>war</type>
</deployable>
</deployables>
</configuration>
<dependencies>
<dependency>
<groupId>org.glassfish.main.deployment</groupId>
<artifactId>deployment-client</artifactId>
<version>3.1.2.2</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>