Ivy, ant and run scripts

I have a project that uses ant for build and ivy for dependencies. I would like to generate start scripts for my project using the classpath based on the dependencies configured in Ivy, especially since the order of the dependencies can be important and must be kept out of order in the ivy configuration.

Has anyone done this before? I also need to create relative paths in the classpath, so I cannot use absolute paths, since this will only work on the machine on which the assembly is being performed.

EDIT: based on feedback, if we cut Ivy out of the equation (make permission to the directory of our choice), then I will probably allow the libs ok list. But how would I generate a class path suitable for starting the script, especially with relative paths (relative to my bin directory)?

eg.

install
    /bin <-- scripts here
    /lib <-- jars here

So, in mine, bin/start.shI need to have a ../lib/jar in front of each link, and not the full path.

Thanks.

+3
source share
4 answers

For many years (2000?) We have had this little script in the way ("make_cp")

#!/usr/bin/perl

my $CLASSPATH="";
my $DIR=shift;
$DIR||="lib";

opendir(LIBDIR, $DIR);
while ($file = readdir(LIBDIR)) {
    $CLASSPATH.=":$DIR/$file" if ($file =~ /\.jar$|\.zip$/);
}
closedir(LIBDIR);
$CLASSPATH=~ s/^://g;
print "$CLASSPATH";

Used as follows:

export CLASSPATH=`make_cp lib`:`make_cp external-lib`
+1
source

, , .

JAR/WAR/ Ant Ivy JAR. , , Ivy Ant , JAR, JAR: s JAR/lib/.

0

, JAR, JAR-:

<zip destfile="abc.jar">
    <zipgroupfileset dir="lib/distributed" includes="*.jar"/>
    <manifest>
        <attribute name="Main-Class" value="com.acme.MyClass"/>
    </manifest>
</zip>

script :

java -jar abc.jar
0

If you are using java 1.6, you can use file globes (ie java -cp "../lib/*"). If you are using an earlier version of Java, and you do not want to use the Vladimir solution, you need to write a script stating that there should be a class path.

So start.sh looks something like this:

cd dirname %0 # change to the bin directory, use %0/.. instead and you can replace ../lib with just /lib
sh set_classpath.sh  # set the classpath
java -cp $CLASSPATH some.package.Main 

and set_classpath.sh will have some Linux magic that sets CLASSPATH equal to something like "../lib/abc.jar:../lib/def.jar"

export CLASSPATH=`ls *.jar | sed 's/[^.jar].jar/..\/lib\/\0:/'`
0
source

Source: https://habr.com/ru/post/1722340/


All Articles