I'm trying to add to my pom an Ant run task to install local dependencies before building the jar.
So i added in my pom this part
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>Install Local Dependencies</id>
<goals>
<goal>run</goal>
</goals>
<phase>validate</phase>
<configuration>
<target>
<echo message="Installing local lib" />
<exec executable="/usr/local/bin/mvn">
<arg value="-f ${lib.dir}/pom.xml clean install " />
</exec>
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.9.6</version>
</dependency>
</dependencies>
</plugin>
but it fails because it tries to launch mvn from the current directory.
Is there a proper way to install an external pom before building the main pom?
Related
I have 2 maven projects. Project A and Project B. Project B is dependent on Project A but not the other way around.
In my project B pom I have this:
<dependency>
<groupId>com</groupId>
<artifactId>ProjectA</artifactId>
<type>pom</type>
<version>1.0-SNAPSHOT</version>
</dependency>
When i try to package the project it fails with this error:
[ERROR] Failed to execute goal on project ProjectB: Could not resolve dependencies for project com:ProjectB:war:1.0-SNAPSHOT: Could not find artifact com:ProjectA:pom:1.0-SNAPSHOT -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project ProjectB: Could not resolve dependencies for project com:ProjectB:war:1.0-SNAPSHOT: Could not find artifact com:ProjectA:pom:1.0-SNAPSHOT
So it can't find my ProjectA pom. Do I need to put it in my project? Where should it be located in my file structure.
For what it's worth, I am using intelliJ IDE.
Thanks in advance.
EDIT: When i run install on projectA I get this error:
The packaging for this project did not assign a file to the build artifact
EDIT2 - Adding ProjectA pom:
<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>
<groupId>edu</groupId>
<artifactId>ProjectA</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>ProjectA</name>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>install-jar-lib</id>
<phase>validate</phase>
<goals>
<goal>install-file</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>prepare-package</id>
<phase>prepare-package</phase>
<configuration>
<target>
<copy file="${basedir}/src/main/webapp/META-INF/context-${app.environment}.xml"
tofile="${basedir}/src/main/webapp/META-INF/context.xml" />
<copy file="${basedir}/src/main/webapp/WEB-INF/web-${app.environment}.xml"
tofile="${basedir}/src/main/webapp/WEB-INF/web.xml" />
<copy file="${basedir}/src/main/resources/log4j-${app.environment}.xml"
tofile="${basedir}/src/main/resources/log4j.xml" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<phase>compile</phase>
<configuration>
<target>
<copy file="${project.build.directory}/classes/log4j-${app.environment}.xml"
tofile="${project.build.directory}/classes/log4j.xml" />
<delete>
<fileset dir="${project.build.directory}/classes" includes="**/*-local.*"/>
<fileset dir="${project.build.directory}/classes" includes="**/*-test.*"/>
<fileset dir="${project.build.directory}/classes" includes="**/*-prod.*"/>
</delete>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>package</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<delete file="${basedir}/src/main/webapp/META-INF/context.xml" />
<delete file="${basedir}/src/main/webapp/WEB-INF/web.xml" />
<tstamp>
<format property="last.timestamp" pattern="yyyyMMddHHmmss"/>
</tstamp>
<property name="build.time" value="${last.timestamp}" />
</target>
<exportAntProperties>true</exportAntProperties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<failOnMissingWebXml>true</failOnMissingWebXml>
<!--<webResources>
<resource>
<directory>src/main/WEB-INF/lib</directory>
<targetPath>WEB-INF/lib</targetPath>
<filtering>false</filtering>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</webResources>-->
</configuration>
</plugin>
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<id>rename-file</id>
<phase>package</phase>
<goals>
<goal>rename</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/${artifactId}-${version}.war</sourceFile>
<destinationFile>${project.build.directory}/ProjectA##${build.time}.war</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
You have to install ProjectA in your local Maven repo (or otherwise make it available in whatever remote repositories your pom.xml or settings.xml point at). For example:
cd whereever/projectA/lives
mvn clean install
This will write com/ProjectA/ProjectA.pom to your local Maven repo and when you do this ...
cd wherever/projectB/lives
mvn clean install
... Maven will resolve ProjectA.pom from that location.
Note: the dependency you have declared on ProjectA:
<dependency>
<groupId>com</groupId>
<artifactId>ProjectA</artifactId>
<type>pom</type>
<version>1.0-SNAPSHOT</version>
</dependency>
... will transitively add all dependencies declared in com:ProjectA to ProjectB's POM, is that definitely your intention? This only makes sense if ProjectA is packaged as a POM, if it is packaged as a JAR then you need to update the dependency declaration in ProjectB to remove this line: <type>pom</type>.
Every time I try to run my JavaFX 8 project, I need to do a clean install with Maven then build project with eclipse. Doing only the clean install will result in an Exception.
How can I make the maven clean install and eclipse build execute in one command.
If I need to add it in my pom.xml, should I put it in my parent pom.xml or all in its children?
Thanks!
Finally got mine working, I just added this lines of code on my parent pom.xml.
<build>
<plugins>
<!-- This will copy all your dependencies to target/libs, which will be
picked up by the ant task below -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/libs</outputDirectory>
<includeScope>compile</includeScope>
<includeScope>runtime</includeScope>
<excludeArtifactIds>javafx</excludeArtifactIds>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>create-javafx-packages</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target xmlns:fx="javafx:com.sun.javafx.tools.ant">
<taskdef uri="javafx:com.sun.javafx.tools.ant" resource="com/sun/javafx/tools/ant/antlib.xml" classpath="${javafx.tools.ant.jar}"/>
<fx:application id="fxApp" name="${project.name}" mainClass="${project.main.class}"/>
<!-- Note: this will overwrite the JAR produced by maven-jar-plugin,
change destfile if you don't want this -->
<fx:jar destfile="${project.build.directory}/../../${project.build.finalName}">
<fx:application refid="fxApp"/>
<fx:fileset dir="${project.build.directory}/../.." includes="target/classes"/>
<fx:resources>
<fx:fileset dir="${project.build.directory}/../.." includes="libs/*.jar"/>
</fx:resources>
</fx:jar>
<fx:deploy outdir="${project.build.directory}/../../javafx-output" outfile="${project.build.finalName}" nativeBundles="all">
<fx:application refid="fxApp"/>
<fx:resources>
<!-- If you changed <fx:jar> above, don't forget to modify the
line below -->
<fx:fileset dir="${project.build.directory}/../.." includes="${project.build.finalName}.jar"/>
<fx:fileset dir="${project.build.directory}/../.." includes="libs/*.jar"/>
</fx:resources>
</fx:deploy>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>javafx</artifactId>
<version>${javafx.version}</version>
<scope>system</scope>
<systemPath>${java.home}/lib/ext/jfxrt.jar</systemPath>
</dependency>
</dependencies>
Try doing the following
mvn clean install eclipse:clean eclipse:eclipse and then do a refresh on the project in eclipse.
HTH,
Keshava.
My pom.xml contains
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warName>${project.artifactId}</warName>
<outputDirectory>${wlp.install.dir}/usr/servers/liberty/apps</outputDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
When I run mvn package I can see this step running:
[INFO] --- maven-war-plugin:2.3:war (default-war) # frontEnd ---
That's great. However, I also want to run a shell script before the war file is created. I tried adding
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<configuration>
<tasks>
<exec dir="${basedir}"
executable="${basedir}/src/main/webapp/concat"/>
</tasks>
</configuration>
</plugin>
before the maven-war plugin, but it does not run. I don't even see antrun in the output of mvn. Adding the <tasks> element to the <configuration> for maven-war-plugin does nothing either.
What can I do to have maven simply run a script as part of mvn package?
The position in the pom.xml is irrelevant, you have to bind the maven-antrun-plugin execution to the correct lifecycle phase (e.g. compile) as shown below:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase> <!-- a lifecycle phase --> </phase>
<configuration>
<target>
<!--
Place any Ant task here. You can add anything
you can add between <target> and </target> in a
build.xml.
-->
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
See The maven-antrun-plugin Usage Page for more details and The Maven Introduction to the Build Lifecycle for further reference.
I use maven-antrun-plugin for init config files for my project. But i need to init config files just once, when i first start to init my dev environment, not each time i launch jetty:run.
If I attach phase to process-resouces for example, each time I launch jetty, my config files are reseted.
So i configured antrun like this :
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target name="init_config_files">
<!-- init files -->
</target>
</configuration>
</execution>
</executions>
</plugin>
If I launch mvn antrun:run, it just return me this error : "[INFO] No ant target defined - SKIPPED". And it is the same thing, if I specify target : "mvn antrun:run -Dtarget=init_config_files".
Try this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>default-cli</id>
<configuration>
<target>
<property name="compile_classpath" refid="maven.compile.classpath" />
<echo message="compile classpath: ${compile_classpath}" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
and run this:
mvn antrun:run
Best solution I have found so far:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>go-live</id>
<configuration>
<target>
<!-- go live! -->
<exec executable="${basedir}/deploy2server.sh" failonerror="true" dir="${basedir}">
<arg value="deploy" />
<arg value="${deploy.to.server}" />
<arg value="${jetty.port.live}" />
</exec>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
and run this:
mvn antrun:run#go-live
This solution avoids the target being run by accident, ie. it does not run just by typing "mvn antrun:run" and it also does not run during regular maven runs. I'm using this for qa auto-deployment in my jenkins instance after all modules incl integration done against the final distribution package have been successfully executed.
I just ran into the same problem and finally figured it out: If you want to run the ant tasks only once, you can set the plugin up like this:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<configuration>
<target name="init_config_files">
<!-- init files -->
</target>
</configuration>
</plugin>
and use mvn antrun:run to execute it. That way, the ant stuff is not bound to any phase.
If you need to run some part of build on special conditions (e.g. once), you can put those parts into a Maven profile and then invoke Maven specifying profile name, e.g. mvn -p init_config_files package
There's this task:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>clean</id>
<phase>clean</phase>
<configuration>
<tasks>
<delete dir="src\test\resources\templates" includeemptydirs="true" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
The problem is: when I run mvn clean, <phase>clean</phase> tells maven to download project dependencies (that don't exist yet) and I get Could not resolve dependencies error.
How to tell maven not to require project dependencies to run this plugin?