I want to extract a tarball-file with *.tar.xz with ant.
But I can only find, bunzip2, gunzip, unzip and untar as goals in ant and none of it seems to work.
So how can I expand a tarball-file with *.tar.xz with ant?
The XZ format is not supported by the default Ant distribution, you'll need the Apache Compress Antlib.
Download the full Antlib with all the dependencies from here (add the three jars ant-compress,common-compress,xz in the lib directory of your ant), and use this task:
<target name="unxz">
<cmp:unxz src="foo.tar.xz" xmlns:cmp="antlib:org.apache.ant.compress"/>
<untar src="foo.tar" dest="."/>
<delete file="foo.tar"/>
</target>
You have to use this two-steps process because even with the additional ant library, the "xz" value is still not supported by the compression attribute of the untar task, the task you'll normally use to extract compressed tars.
In case somebody else like myself wants to do the same with maven managing ant.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<dependencies>
<!-- Optional: May want to use more up to date commons compress, add this dependency
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.10</version>
</dependency> -->
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-compress</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>unpack</id>
<phase>generate-sources</phase>
<goals><goal>run</goal></goals>
<configuration>
<target name="unpack">
<taskdef resource="org/apache/ant/compress/antlib.xml" classpathref="maven.plugin.classpath"/>
<unxz src="${xz.download.file}" dest="${tar.unpack.directory}" />
<untar src="${tar.unpack.file}" dest="${final.unpack.directory}"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
Related
Have a project with several module projects and itself having other module projects. I have certain modules generating a special artifact type '.kar', and I am deploying this to artifactory during maven deploy phase.
Now I want to find a way by using this existing pom to download these specific artifacts from artifactory by version.
mvn dependency:copy <> allows me to download this per specific artifact.
I want this to be done via the pom file which generates these artifacts. Problem is when I use the dependency:copy, it only runs on the current pom which may or may not have the special artifact.
If I use it in then it re-deploys all the artifacts and downloads the special artifact correctly. This is not right solution though.
You could add a new module to your project that has <dependencies> to all of your .kar artifacts. In the POM file of this new module you can use the copy-dependencies goal of the maven-dependency-plugin.
<project>
<!-- Integrate this module into your multi-module project. -->
<parent>
<groupId>my.group.id</groupId>
<artifactId>my-parent-pom</artifactId>
<version>1.0.0-SNAPSHOT</version<
</parent>
...
<!-- Add dependencies for all your .kar artifacts. -->
<dependencies>
<dependency>
<groupId>my.group.id</groupId>
<artifactId>kar-artifact-1</artifactId>
<version>${project.version}</version>
<type>kar</type>
</dependency>
<dependency>
<groupId>my.group.id</groupId>
<artifactId>kar-artifact-2</artifactId>
<version>${project.version}</version>
<type>kar</type>
</dependency>
...
</dependencies>
<build>
<plugins>
<!-- Use the maven-dependency-plugin to copy your .kar artifacts. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy-kar-artifacts</id>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeTypes>kar</includeTypes>
</configuration>
</execution>
</executions>
<plugin>
</plugins>
</build>
</project>
Please, I am new to maven and trying to build my first maven project. So, here are a few things I did:
from my command line into a directory called MavenProject I created:
mvn archetype:generate
and then choose a number to apply number, I entered 15 then;
Choose com.dyuproject.protostuff.archetype:basic-webapp version:
I chose version 1.0.7
groupId: com.henry
artifactId: HibernateTest
and the rest, I just entered..
and the project was created but then I typed in mvn eclipse:eclipse, I got an error that there was no pom.xml file even though I can see there is one in my mavenProject. so, I changed into the HibernateTest directory and in that directory, I tried the mvn eclipse:eclipse command again but this time, it gave the eorror:
Plugin com.dyuproject.protostuff:protostuff-maven-plugin:1.0.2-SNAPSHOT or one of its
dependencies could not be resolved: Failed to read artifact descriptor for
com.dyuproject.protostuff:protostuff-maven-plugin:jar:1.0.2-SNAPSHOT: Could not find artifact
com.dyuproject.protostuff:protostuff-maven-plugin:pom:1.0.2-SNAPSHOT
I tried to solve this by going to mvnrepository.com and found the protostuff maven and added the dependencies but still couldn't solve it. here is my pom.xml file:
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLS$
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_$
<parent>
<artifactId>Hibernate</artifactId>
<groupId>com.henry</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.henry</groupId>
<artifactId>Hibernate-model</artifactId>
<name>Hibernate :: model</name>
<packaging>jar</packaging>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-maven-plugin</artifactId>
<version>${protostuff.version}</version>
<configuration>
<protoModules>
<protoModule>
<source>src/main/resources/com/henry/model/model.proto</source>
<outputDir>src/main/java</outputDir>
<output>java_bean</output>
<encoding>UTF-8</encoding>
<options>
<property>
<name>generate_field_map</name>
</property>
<property>
<name>separate_schema</name>
</property>
<property>
<name>builder_pattern</name>
</property>
<property>
<name>generate_helper_methods</name>
</property>
</options>
</protoModule>
</protoModules>
</configuration>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-core</artifactId>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-maven-plugin</artifactId>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-codegen</artifactId>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-core</artifactId>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-maven-plugin</artifactId>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-codegen</artifactId>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-compiler</artifactId>
<version>1.0.7</version>
</dependency>
</dependencies>
</project>
Any help will be appreciated. Sorry am a newbie :)
First try to build the project on the command line: mvn install. That should succeed.
But it looks like it won't, as it is looking for a SNAPSHOT dependency version of ${protostuff.version}. When I look in the Maven central repository, there's really only release versions (as it should be). Somehow you have to fix that, probably in your parent project.
The POM file should be in the root of the project and called pom.xml. Where you find the POM file called pom.xml is the root of the project :)
Only use eclipse:eclipse as a last resort. If you have free choice of Eclipse, and you have no wizardry in your Maven projects, you should be able to use the m2e (m2eclipse) Eclipse plugin.
That's an Eclipse plugin, not a Maven plugin, so no additional steps are needed on the command line. Just go into Eclipse, make sure the m2e plugin is installed. Then import your project (Import, "Existing Maven Projects").
All the files that Eclipse needs for its own bookkeeping should be created upon import and be based on the POM file. I.e. .classpath, .project and .settings (folder). If you have any of those prior to importing into Eclipse, you may be better off removing them (they may be remnants of your eclipse:eclipse attempts.
I am using wagon-maven-plugin to scp my WAR file to the server. It works fine. My next step is to perform some commands on the server (mkdir, etc). Is there a plugin that helps me do that? Is there a way to work it out using wagon-maven-plugin?
I am relatively new to mvn. Any help would be appreciated.
Any suggestions?
I was able to run ssh commands with exec-maven-plugin. It is a powerful maven plugin to do all sorts of hack and also run commands. For anyone interested in the solution
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>sh</executable>
<arguments>
<!-- Shell script location -->
<argument>runscript.sh</argument>
<!-- arg #1 -->
<argument>${file_1}</argument>
</arguments>
</configuration>
</plugin>
Another solution I found was to run maven-antrun-plugin. I would not recommend it since it runs ANT tasks and there are a lot of dependencies to it. But its handy if you would need to run ant tasks via maven.
<plugin>
<inherited>false</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<configuration>
<target>
<loadproperties srcFile="deploy.properties" />
<ftp action="send" server="server"
remotedir="/a/b" userid="usr"
password="pw" depends="no"
verbose="yes" binary="yes">
<fileset dir="modules/my-module/target">
<include name="file.zip" />
</fileset>
</ftp>
<!-- calls deploy script -->
<sshexec host="host" trust="yes"
username="usr" password="pw"
command="sh /my/script.sh" />
<!-- SSH -->
<taskdef name="sshexec"
classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec"
classpathref="maven.plugin.classpath" />
<taskdef name="ftp"
classname="org.apache.tools.ant.taskdefs.optional.net.FTP"
classpathref="maven.plugin.classpath" />
</target>
</configuration>
...
<dependencies>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-commons-net</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>jsch</groupId>
<artifactId>jsch</artifactId>
<version>0.1.29</version>
</dependency>
</dependencies>
</plugin>
Hope that helps!
I need to build project with subprojects and main project is the Maven project, one of the subprojects - is the Ant project.
I need to compile all projects from one main pom.xml
I have found solution How to wrap an Ant build with Maven? and it's answer is correct, but not for my project. Because when my ant project required Ant v. 1.8.x, but on build with the
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b3</version>
<exclusions>
<exclusion>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.8.1</version>
</dependency>
</dependencies>
<modules>
<module>Bundles/I_AboutForm</module>
<module>Bundles/I_AppVars</module>
</modules>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-resources</phase>
<configuration>
<!--<taskdef resource="net/sf/antcontrib/antlib.xml" classpathref="maven.plugin.classpath" />-->
<tasks>
<ant antfile="MainApplication/build.xml" target="compile"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
maven downloaded Ant v. 1.7.1 and uses him on build (in the local repo has Ant v.1.8.1).
I think, may be trouble in the dependings of the ant-contrib 1.0b3 - may be ant-contrib depends on Ant v. 1.7.1?
Please advice me how to build Ant v. 1.8.x project in Maven.
Thanks, best regards, Arthur.
looking at the version of the plugin 1.7, it seems to use the ant version 1.8.2
http://maven.apache.org/plugins/maven-antrun-plugin/dependencies.html
Try to specify the version 1.7 of the plugin maven-antrun-plugin
for example:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
I'm trying to upload a file using an Ant task. If I use Ant directly the file is uploaded, but if I call the ant task via Maven (using the maven-antrun-plugin) I get the following error:
An Ant BuildException has occured: The following error occurred while executing this line:
/home/me/proj/build.xml:15: Problem: failed to create task or type ftp
Cause: the class org.apache.tools.ant.taskdefs.optional.net.FTP was not found.
This looks like one of Ant's optional components.
Action: Check that the appropriate optional JAR exists in
-ANT_HOME/lib
ant-commonsnet.jar is clearly available to Ant:
$ ls $ANT_HOME/lib | grep ant-commons-net
ant-commons-net.jar
Is the Ant classpath defined separately for maven-antrun-plugin, or am I missing something?
ant-commons-net.jar is clearly available to Ant
Yes, but Maven and the maven-antrun-plugin is not using your local Ant install.
Is the Ant classpath defined separately for maven-antrun-plugin, or am I missing something?
The way to use Ant Tasks not included in Ant's default jar is documented in Using tasks not included in Ant's default jar (which should definitely help):
To use Ant tasks not included in the
Ant jar, like Ant optional or custom
tasks you need to add the dependencies
needed for the task to run to the
plugin classpath and use the
maven.plugin.classpath reference if
needed.
<project>
<modelVersion>4.0.0</modelVersion>
<artifactId>my-test-app</artifactId>
<groupId>my-test-group</groupId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>ftp</id>
<phase>deploy</phase>
<configuration>
<target>
<ftp action="send" server="myhost" remotedir="/home/test" userid="x" password="y" depends="yes" verbose="yes">
<fileset dir="${project.build.directory}">
<include name="*.jar" />
</fileset>
</ftp>
<taskdef name="myTask" classname="com.acme.MyTask" classpathref="maven.plugin.classpath"/>
<myTask a="b"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-commons-net</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.6.5</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
As Pascal has mentioned, the maven-antrun-plugin is not using the ant specified by your $ANT_HOME environment variable, and the configuration that he's mentioned is probably the best way to do it consistently from a pure maven perspective.
However, the jar can be stored in $USER_HOME/.ant/lib instead of $ANT_HOME/lib, these jars should be available on the classpath for any instance of ant that is run by that user.
Note that your ant script cannot assume that the jars are present, and that the jars are only placed on the classpath at startup, so if the script defines a setup target to download the jars into $USER_HOME/.ant/lib, then this target would have to be run in a "separate-ant-session", before and is invoked again to execute the task that depends on the jar.
The only potential benefit that you may derive from this approach is that the Ant script may be runnable from maven and Ant.
There is a classpath property which can be set in <tasks> section of maven-antrun-plugin.
For instance,
<property name="classpath" refid="maven.compile.classpath"/>