Download frameworks using ant/maven
Table of Contents
1 Download dependencies with ant
Ant scripts can use a Maven plugin to load (defined) dependencies, i.e., to load jar-files (libraries) from the central or other remote Maven repositories.
In the following the Maven plugin is used to load the database driver
for the HSQLD and MySQL database and the necessary libraraies for
Hibernate, Hibernate-Tools and the Logger log4j. The files are saved
in a local repository /copybase/lib. The dependencies are define in
the <artifact:dependencies>
) tag. angegeben.
- Create directory
/copybase/lib
(will be used instead of User_Home/.m2, the default root directory of the repository)
- Copy the following to /copybase/lib/build.xml. Observe that the localRepository is set to the current directory /copybase/lib.
<?xml version="1.0"?> <project name="SchulungBMC_Dependencies" default="db" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant" > <artifact:dependencies pathId="dependency.classpath"> <localRepository path="./"></localRepository> <!-- --> <remoteRepository id="maven2-repository.dev.java.net" url="http://download.java.net/maven/2" /> <!-- --> <dependency groupId="hsqldb" artifactId="hsqldb" version="1.8.0.7" /> <dependency groupId="mysql" artifactId="mysql-connector-java" version="5.0.5" /> <dependency groupId="org.hibernate" artifactId="hibernate" version="3.2.5.ga" /> <dependency groupId="org.hibernate" artifactId="hibernate-tools" version="3.2.0.beta9a" /> <dependency groupId="log4j" artifactId="log4j" version="1.2.14" /> </artifact:dependencies> <!-- --> <target name="db"> </target> </project>
- Run ant in a command-tool:
cd /copybase/lib ant
Ant executes the steps defined in the <target>
tags. In the
following example the ant script runs the static main method of file
hsqldb-1.8.0.7.jar stored in directory lib/hsqldb/hsqldb/1.8.0.7.
The jar file has been defined as dependency in the ant script abeove.
The <java>
target defines the command:
java -classpath<path> <args>
- Create directories /copybase/database and /copybase/test
- Copy the following to /copybase/test/build.xml. Obserevt that the data.dir and the classpath are set to match /copybase/lib. Run ant. The database will be empty.
<?xml version="1.0"?> <project name="SchulungBMC_TestDb" default="db" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant" > <!-- --> <property name="data.dir" value="../database" /> <!-- --> <target name="db" description="Runs HSQLDb management GUI on data.dir" /> <java classname="org.hsqldb.util.DatabaseManager" fork="yes" > <classpath path="../lib/hsqldb/hsqldb/1.8.0.7/hsqldb-1.8.0.7.jar" /> <arg value="-driver" /> <arg value="org.hsqldb.jdbcDriver" /> <arg value="-url" /> <arg value="jdbc:hsqldb:${data.dir}/bookcase" /> <arg value="-user" /> <arg value="sa" /> </java> </project>
Date: 2011-02-11 Fr
HTML generated by org-mode 7.4 in emacs 22