You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Laird Nelson <lj...@alumni.amherst.edu> on 2003/09/22 19:09:16 UTC

pom.resources question

I'm trying to figure out the syntax to use in the POM for the 
<resources> element.

Specifically, I use maven -f project.xml a lot, and the <directory> 
reference is not being resolved properly.

Originally, I had something like this:

<resources>
  <resource>
    <directory>src/java/foo/bar</directory>
    ...

...but if I run maven -f project.xml from somewhere deep inside my 
project, that relative path is now relative to my current directory, not 
the directory containing project.xml.

So I tried to absolutize this path, like this:

    <directory>${maven.src.dir}/src/java/foo/bar</directory>

...which didn't work, and then like this:

    <directory>${pom.sourceDirectory}/foo/bar</directory>

...which didn't work either.  Ideas?

Laird


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: My Scripts Are Your Scripts

Posted by Anthony Vito <vi...@mnis.com>.
I have cut out my one page of documentation on these helper scripts and
placed it here http://www.cs.oswego.edu/~vito/commandLineTools.html  It
reads pretty easy. Let me know what you think.

-Anthony Vito

> snip all


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


My Scripts Are Your Scripts

Posted by Anthony Vito <vi...@mnis.com>.
Hello List,
  I've been following the list for a while now. I love using Maven at
the command line. However, I found myself jumping all over and having
all sorts of terminals open and it was slowing me down too much. So I
wrote some shell functions and scripts ( as I imagine many others have
too ) to help me be more productive at the command line. Since Maven has
such a nice project structure it was fairly easy to create functions and
scripts to help out at the command line. My hope is to get some sort of
"contrib" going, if there isn't already one, with scripts like this.
Here's what I came up with. The 4 files are also attached because email
probably will mess up the formatting some what. They are just small text
files and should post just fine. These are bash scripts.... they "might"
work in cy-win.

- Anthony Vito 

There are 4 files here
1.) MavenFunctions ( Shell functions )
2.) javacproj ( A javac wrapper script that uses maven dependencies from
a goal )
3.) runproj ( A java wrapper script that use maven deps, and accepts
.java files as input. )
4.) mavenproj ( A maven wrapper script that executes goals at the top of
the project no matter where you are. )



#MavenFunctions(Place this somewhere in your PATH /usr/local/bin for me)

##########################
# Maven Helper Functions #
##########################

# List the functions in this file
mavenhelpers() {
  cat /usr/local/bin/MavenFunctions | grep \(\)
}

# If you are in project tree, ie
#.../someproject/src/(test|java)/some/package
# This will bring you to the project root.
ptop() {
  pushd . > /dev/null
  move="yes"
  dir=`pwd`
  curdir=$dir
  bname=`basename $curdir`
  while [ $bname != "src" ]; do
    if [ $bname == "/" ]; then
      echo "You Aren't In A Project Tree"
      move="no"
      popd > /dev/null
      return 1;
    fi
    cd ..
    curdir=`pwd`
    bname=`basename $curdir`
  done
  if [ $move == "yes" ]; then
    popd > /dev/null
    cd $curdir
    # one more up is the top
    cd ..
  fi
  return 0;
}

# If you are in a project tree, ie
#.../someproject/src/(test|java)/some/package
# This is jump you to the same location on the other side of the tree.
# For example.
# if you are in src/java/some/package/is/cool, xcd will take you to
# src/test/some/package/is/cool. This is most helpful.
xcd() {
  pushd . > /dev/null
  move="yes"
  dir=`pwd`
  curdir=$dir
  bname=`basename $curdir`
  while [ $bname != "src" ]; do
    if [ $bname == "/" ]; then
      echo "You Aren't In A Project Tree"
      move="no"
      popd > /dev/null
      return 1;
    fi
    cd ..
    curdir=`pwd`
    bname=`basename $curdir`
  done
  popd > /dev/null
  if [ $move == "yes" ]; then
    if [ -d $curdir/java ] && [ -d $curdir/test ]; then
      # +5 for length of /java or /test
      curdirlength=$((`expr length $curdir`))
      baselength=$(($curdirlength+5))
      dirlength=$((`expr length $dir`))
      type="`expr substr $dir $(($curdirlength+2)) 4`"
      case $type in
        "java" ) type="test";;
        "test" ) type="java";;
        * ) type="none"
            echo "Project Tree Format Unknown"
        return 1;
      esac
      if [ $type != "none" ]; then
        cd $curdir"/$type/"`expr substr $dir $(($baselength+2))
$dirlength`
      fi
    else
      echo "Projected Tree Not Properly Formatted ie src/java src/java"
      return 1;
    fi
  fi
  return 0;
}
# END MavenFunctions.........##

# --- javacproj --- javac wrapper that uses maven's structure

#!/bin/bash

# This script will act almost like javac. I always liked
# the simplicity of "javac *.java" in fact, I have it
# aliased ;)  What this does is use a classpath file
# called .mavenclasspath, which is created from a maven
# goal that is in my "master" maven.xml....
#   <!--
#    This goal writes out the current dependency classpath to a file.
#    This is useful for any project / script external to maven, because
#    it will be able to use the same classpath, and dependencies, from
#    the repository.
#   -->
#  <goal name="createDeps">
#    <!-- read in dependencies and construct a class path -->
#    <ant:path id="classpath">
#    <ant:path refid="maven.dependency.classpath"/>
#      <ant:pathelement path="${maven.build.dest}"/>
#    </ant:path>
#    <!-- set the ID to a property -->
#    <ant:property name="class.path" refid="classpath"/>
#    <ant:echo
file="${basedir}/.mavenclasspath">${class.path}</ant:echo>
#  </goal>
#
   #  <!--
#    This does the same thing as the createDeps goal, but does it as
#    a preGoal of java:compile, making it difficult for dependencies
#    and the .mavenclasspath file to be inconsistent.
#   -->
#  <preGoal name="java:compile">
#    <attainGoal name="createDeps"/>
#  </preGoal>
#
# Oh, there it is ;)
#
# It also targets the default classes directory
projectTop/target/classes
# ( I know it doesn't handle the test side properly by targeting
test-classes
#  if you're on the test side, you want to do it? ;) )
#
# So to use this thing you just do a "maven java:compile", or
# "maven createDeps" directly, either way is fine. Then hop into
# your source tree. Then, any time you need to compile stuff with
# the right classpath, just use "javacproj *.java". BAM good stuff.
#

pushd . > /dev/null
compile="yes"
dir=`pwd`
curdir=$dir
bname=`basename $curdir`
while [ $bname != "src" ]; do
  if [ $bname == "/" ]; then
    echo "You Aren't In A Project Tree"
    compile="no"
    popd > /dev/null
    break
  fi
  cd ..
  curdir=`pwd`
  bname=`basename $curdir`
done
if [ $compile == "yes" ]; then
  cd ..
  # now I should be looking at a target directory
  # if not... I'm making one
  if [ ! -d target/classes ]; then
    if [ ! -d target ]; then
      mkdir target;
    fi
    mkdir target/classes
  fi
  targetdir=`pwd`/target/classes
  cpFile=`pwd`/.mavenclasspath
  popd > /dev/null
  if [ -f $cpFile ]; then
    classpath=`cat $cpFile`
    exec javac -classpath $classpath -d $targetdir $@
  else
    echo "No Maven Classpath Found, Run 'maven createDeps' On The
Project."
    compile="no"
  fi
else
  echo "No Compile Performed"
fi

# End --- javacproj -----

# --- runproj --- java wrapper that uses Maven's structure

#!/bin/bash

# This exciting script is the compliment to javacproj,
# with a helpful twist as always. It takes care of the
# classpath thing by using the same .mavenclasspath file
# as javacproj ( see javacproj for more details there )
# Also... I always hated having to type fully qualified
# paths to run the main of java class ( don't you )
# "java org.javavr.hotornot.ShowHotGirls".. it's a regular
# PITA. This script lets you be in the src directory and
# execute by giving the .java file as input. So you can
# use tab completion to run your mains, ain't that swell?
#
# Example.
# you are in "src/java/org/javavr/hotornot"
# command "runproj ShowHotGirls.java" will execute the main
# in ShowHotGirls.java. ( And show you the hot girls! )
#
# NOTE: It doesn't handle JVM arguments yet.
#       Want to do it? ;)

pushd . > /dev/null
run="yes"
dir=`pwd`
curdir=$dir
bname=`basename $curdir`
packagename=$bname
while [ $bname != "src" ]; do
  if [ $bname == "/" ]; then
    echo "You Aren't In A Project Tree"
    run="no"
    popd > /dev/null
    break
  fi
  cd ..
  curdir=`pwd`
  bname=`basename $curdir`
  packagename=$bname"."$packagename
done
packagelength=`expr length $packagename`
packagename=`expr substr $packagename 10 $(($packagelength-8))`
if [ $run == "yes" ]; then
  cd ..
  # now I should be looking at a target directory
  # if not... get out of here
  if [ ! -d target/classes ]; then
    echo "You Haven't Compiled Anything Yet"
    exit
  fi
  basedir=`pwd`
  cpFile=$basedir/.mavenclasspath
  popd > /dev/null
  if [ -f $cpFile ]; then
    if [ "X$1" == "X" ]; then
      echo "Usage: runproj [ classname | sourcefile ]"
      exit
    fi
    classpath=`cat $cpFile`
    classname=$1
    length1=`expr length $classname`
    if [ "X`expr substr $classname $(($length1 - 4)) 5`" == "X.java" ];
then
      classname=`expr substr $classname 1 $(($length1 - 5))`
    fi
    shift
    echo "Executing Class: $packagename.$classname $@"
    #exec java -Dmavenbasedir=$basedir -Xmx512m -verbosegc
-Xrunhprof:cpu=samples,thread=y -classpath $classpath
$packagename"."$classname $@
    exec java -Dmavenbasedir=$basedir -Xmx512m -classpath $classpath
$packagename"."$classname $@
  else
    echo "No Maven Classpath Found, Run 'maven createDeps' On The
Project."
    run="no"
  fi
else
  echo "No Run Performed"
fi

# --- End --- runproj

# --- mavenproj --- maven wrapper to execute from top of project

#!/bin/bash

# Oh this one is real fun. This was more of a
# "putting it all together" script. This simple
# guy lets you execute maven goals on the project
# while you are sitting in the src or test tree.
# Very helpful, let me tell you....

. MavenFunctions

ptop
if [ $? == 0 ]; then
  echo "Executing Goal From Project Top: `pwd`"
  maven $@
else
  echo "No Goal Executed"
fi

# --- End --- mavenproj



Re: pom.resources question

Posted by Andy Jefferson <an...@ajsoft.net>.
On Monday 22 Sep 2003 18:51, Laird Nelson wrote:
> Laird Nelson wrote:
> > So I tried to absolutize this path, like this:
> >
> >    <directory>${maven.src.dir}/src/java/foo/bar</directory>
> > ...which didn't work, and then like this:
> >
> >    <directory>${pom.sourceDirectory}/foo/bar</directory>
> > ...which didn't work either.  Ideas?
>
> I can get it to work with
> <directory>${basedir}/src/java/foo/bar</directory>.  Is that the
> recommended way?

Not sure if there is a "recommended" way, but thats what I've used. Its got to 
be down to when the various variables are initialised, and AFAIK basedir is 
available *always*.

-- 
Andy


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: pom.resources question

Posted by Jason van Zyl <jv...@maven.org>.
On Mon, 2003-09-22 at 19:34, dion@multitask.com.au wrote:
> AFAIK, yes. 
> 
> It's the usual, if it's absolute use as is. If it's not, make it absolute 
> by using basedir.

Coolio.

> --
> dIon Gillard, Multitask Consulting
> Blog:      http://blogs.codehaus.org/people/dion/
> 
> 
> Jason van Zyl <jv...@maven.org> wrote on 23/09/2003 09:18:34 AM:
> 
> > On Mon, 2003-09-22 at 18:36, dion@multitask.com.au wrote:
> > > These are all fixed in CVS.
> > > 
> > > With the next release, the <directory> will be relative to the 
> project.xml 
> > > file.
> > 
> > If ${basedir} is present will it still be honoured?
> > 
> > > Are you using CVS HEAD?
> > > --
> > > dIon Gillard, Multitask Consulting
> > > Blog:      http://blogs.codehaus.org/people/dion/
> > > 
> > > 
> > > Laird Nelson <lj...@alumni.amherst.edu> wrote on 23/09/2003 
> 03:51:34 
> > > AM:
> > > 
> > > > Laird Nelson wrote:
> > > > 
> > > > > So I tried to absolutize this path, like this:
> > > > >
> > > > >    <directory>${maven.src.dir}/src/java/foo/bar</directory>
> > > > >
> > > > > ...which didn't work, and then like this:
> > > > >
> > > > >    <directory>${pom.sourceDirectory}/foo/bar</directory>
> > > > >
> > > > > ...which didn't work either.  Ideas? 
> > > > 
> > > > I can get it to work with 
> > > > <directory>${basedir}/src/java/foo/bar</directory>.  Is that the 
> > > > recommended way?
> > > > 
> > > > Laird
> > > > 
> > > > 
> > > > 
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > > > For additional commands, e-mail: users-help@maven.apache.org
> > > > 
> > > 
> > > 
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > > For additional commands, e-mail: users-help@maven.apache.org
> > -- 
> > jvz.
> > 
> > Jason van Zyl
> > jason@zenplex.com
> > http://tambora.zenplex.org
> > 
> > In short, man creates for himself a new religion of a rational
> > and technical order to justify his work and to be justified in it.
> > 
> >   -- Jacques Ellul, The Technological Society
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
-- 
jvz.

Jason van Zyl
jason@zenplex.com
http://tambora.zenplex.org

In short, man creates for himself a new religion of a rational
and technical order to justify his work and to be justified in it.
  
  -- Jacques Ellul, The Technological Society


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: pom.resources question

Posted by di...@multitask.com.au.
AFAIK, yes. 

It's the usual, if it's absolute use as is. If it's not, make it absolute 
by using basedir.
--
dIon Gillard, Multitask Consulting
Blog:      http://blogs.codehaus.org/people/dion/


Jason van Zyl <jv...@maven.org> wrote on 23/09/2003 09:18:34 AM:

> On Mon, 2003-09-22 at 18:36, dion@multitask.com.au wrote:
> > These are all fixed in CVS.
> > 
> > With the next release, the <directory> will be relative to the 
project.xml 
> > file.
> 
> If ${basedir} is present will it still be honoured?
> 
> > Are you using CVS HEAD?
> > --
> > dIon Gillard, Multitask Consulting
> > Blog:      http://blogs.codehaus.org/people/dion/
> > 
> > 
> > Laird Nelson <lj...@alumni.amherst.edu> wrote on 23/09/2003 
03:51:34 
> > AM:
> > 
> > > Laird Nelson wrote:
> > > 
> > > > So I tried to absolutize this path, like this:
> > > >
> > > >    <directory>${maven.src.dir}/src/java/foo/bar</directory>
> > > >
> > > > ...which didn't work, and then like this:
> > > >
> > > >    <directory>${pom.sourceDirectory}/foo/bar</directory>
> > > >
> > > > ...which didn't work either.  Ideas? 
> > > 
> > > I can get it to work with 
> > > <directory>${basedir}/src/java/foo/bar</directory>.  Is that the 
> > > recommended way?
> > > 
> > > Laird
> > > 
> > > 
> > > 
---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > > For additional commands, e-mail: users-help@maven.apache.org
> > > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> -- 
> jvz.
> 
> Jason van Zyl
> jason@zenplex.com
> http://tambora.zenplex.org
> 
> In short, man creates for himself a new religion of a rational
> and technical order to justify his work and to be justified in it.
> 
>   -- Jacques Ellul, The Technological Society
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: pom.resources question

Posted by Jason van Zyl <jv...@maven.org>.
On Mon, 2003-09-22 at 18:36, dion@multitask.com.au wrote:
> These are all fixed in CVS.
> 
> With the next release, the <directory> will be relative to the project.xml 
> file.

If ${basedir} is present will it still be honoured?

> Are you using CVS HEAD?
> --
> dIon Gillard, Multitask Consulting
> Blog:      http://blogs.codehaus.org/people/dion/
> 
> 
> Laird Nelson <lj...@alumni.amherst.edu> wrote on 23/09/2003 03:51:34 
> AM:
> 
> > Laird Nelson wrote:
> > 
> > > So I tried to absolutize this path, like this:
> > >
> > >    <directory>${maven.src.dir}/src/java/foo/bar</directory>
> > >
> > > ...which didn't work, and then like this:
> > >
> > >    <directory>${pom.sourceDirectory}/foo/bar</directory>
> > >
> > > ...which didn't work either.  Ideas? 
> > 
> > I can get it to work with 
> > <directory>${basedir}/src/java/foo/bar</directory>.  Is that the 
> > recommended way?
> > 
> > Laird
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
-- 
jvz.

Jason van Zyl
jason@zenplex.com
http://tambora.zenplex.org

In short, man creates for himself a new religion of a rational
and technical order to justify his work and to be justified in it.
  
  -- Jacques Ellul, The Technological Society


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: pom.resources question

Posted by di...@multitask.com.au.
These are all fixed in CVS.

With the next release, the <directory> will be relative to the project.xml 
file.

Are you using CVS HEAD?
--
dIon Gillard, Multitask Consulting
Blog:      http://blogs.codehaus.org/people/dion/


Laird Nelson <lj...@alumni.amherst.edu> wrote on 23/09/2003 03:51:34 
AM:

> Laird Nelson wrote:
> 
> > So I tried to absolutize this path, like this:
> >
> >    <directory>${maven.src.dir}/src/java/foo/bar</directory>
> >
> > ...which didn't work, and then like this:
> >
> >    <directory>${pom.sourceDirectory}/foo/bar</directory>
> >
> > ...which didn't work either.  Ideas? 
> 
> I can get it to work with 
> <directory>${basedir}/src/java/foo/bar</directory>.  Is that the 
> recommended way?
> 
> Laird
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: pom.resources question

Posted by Laird Nelson <lj...@alumni.amherst.edu>.
Laird Nelson wrote:

> So I tried to absolutize this path, like this:
>
>    <directory>${maven.src.dir}/src/java/foo/bar</directory>
>
> ...which didn't work, and then like this:
>
>    <directory>${pom.sourceDirectory}/foo/bar</directory>
>
> ...which didn't work either.  Ideas? 

I can get it to work with 
<directory>${basedir}/src/java/foo/bar</directory>.  Is that the 
recommended way?

Laird


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org