problem creating WAR file with ant

Discussion in 'Java' started by Laura Schmidt, Nov 18, 2012.

  1. Hello,

    I have a web project W, which uses a java library L. This "usage" is
    based on the eclipse confguration: I just told eclipse that W uses L.
    Since then, the java compiler finds the source files of L when compiling W.

    I delpoy the web project as a war file using ant:

    <target name="buildwar">
    <war basedir="war" destfile="myproject.war"
    webxml="war/WEB-INF/web.xml">
    </war>

    When I deploy this war file to a tomcat server, the class files of L are
    missing.

    I tried to resolve this by adding a symbolic link pointing from
    $W/WEB-INF/classes to $L/classes. This worked, but after some rebuilds
    this link was deleted somehow. I assume that the contents of
    $w/WEB-INF/classes is deleted sometimes by some build procedures.

    Then, I tried to add the dependency in the ant file:

    <target name="buildwar">
    <war ...>
    <fileset dir="path/to/L/classes"/>
    </war>
    </target>

    But this also didn't work.

    Within the produced war file, the class files of L were in the root
    directory. I believe that the class files should be placed into the
    WEB-INF/classes directory of the war file.

    However, this problem cannot be new and there must be a standard way to
    do it. I would be glad if someone can tell me how to do it right.

    Thanks
    Laura
    Laura Schmidt, Nov 18, 2012
    #1
    1. Advertising

  2. Laura Schmidt

    Arne Vajhøj Guest

    On 11/18/2012 11:53 AM, Laura Schmidt wrote:
    > I have a web project W, which uses a java library L. This "usage" is
    > based on the eclipse confguration: I just told eclipse that W uses L.
    > Since then, the java compiler finds the source files of L when compiling W.
    >
    > I delpoy the web project as a war file using ant:
    >
    > <target name="buildwar">
    > <war basedir="war" destfile="myproject.war"
    > webxml="war/WEB-INF/web.xml">
    > </war>
    >
    > When I deploy this war file to a tomcat server, the class files of L are
    > missing.
    >
    > I tried to resolve this by adding a symbolic link pointing from
    > $W/WEB-INF/classes to $L/classes. This worked, but after some rebuilds
    > this link was deleted somehow. I assume that the contents of
    > $w/WEB-INF/classes is deleted sometimes by some build procedures.
    >
    > Then, I tried to add the dependency in the ant file:
    >
    > <target name="buildwar">
    > <war ...>
    > <fileset dir="path/to/L/classes"/>
    > </war>
    > </target>
    >
    > But this also didn't work.
    >
    > Within the produced war file, the class files of L were in the root
    > directory. I believe that the class files should be placed into the
    > WEB-INF/classes directory of the war file.
    >
    > However, this problem cannot be new and there must be a standard way to
    > do it. I would be glad if someone can tell me how to do it right.


    The war task has a nested lib element.

    There is an example at the bottom at:
    http://ant.apache.org/manual/Tasks/war.html

    Use that!

    Arne
    Arne Vajhøj, Nov 18, 2012
    #2
    1. Advertising

  3. On 11/18/2012 06:01 PM, Arne Vajhøj wrote:
    > On 11/18/2012 11:53 AM, Laura Schmidt wrote:


    Hi Arne!

    >> Within the produced war file, the class files of L were in the root
    >> directory. I believe that the class files should be placed into the
    >> WEB-INF/classes directory of the war file.
    >>
    >> However, this problem cannot be new and there must be a standard way to
    >> do it. I would be glad if someone can tell me how to do it right.

    >
    > The war task has a nested lib element.
    >
    > There is an example at the bottom at:
    > http://ant.apache.org/manual/Tasks/war.html
    >
    > Use that!


    If I use that I''ll have to create a jar file for the library every time
    I make changes to it. Instead of the lib element I used a symbolic link
    in the WEB-INF/lib directory of the project pointing to the library's
    jar file. This is the way I always did it.

    But now I find it useful to avoid this step by directly including the
    library's class files, which are located under $L/classes. What about this?

    If including the class files directly, where in the war file do they belong?

    Thanks!
    Laura
    Laura Schmidt, Nov 19, 2012
    #3
  4. Laura Schmidt

    Lew Guest

    Laura Schmidt wrote:
    >>> Within the produced war file, the class files of L were in the root
    >>> directory. I believe that the class files should be placed into the
    >>> WEB-INF/classes directory of the war file.


    Neither is correct.

    The JAR of L should be in the lib/ subdirectory within the WAR.

    RTFM.

    >>> However, this problem cannot be new and there must be a standard way to
    >>> do it. I would be glad if someone can tell me how to do it right.


    There is, and the documentation tells you what it is.

    >> The war task has a nested lib element.


    As indeed, a WAR has a nested lib/ subdirectory. As per the docs.

    >> There is an example at the bottom at:
    >> http://ant.apache.org/manual/Tasks/war.html
    >>
    >> Use that!


    > If I use that I''ll have to create a jar [sic] file for the library every time
    > I make changes to it.


    Yeah, so? Why wouldn't you? You say that like it's an argument against
    doing things the right way.

    > Instead of the lib element I used a symbolic link
    > in the WEB-INF/lib directory of the project pointing to the library's
    > jar file. This is the way I always did it.


    It's the wrong way.

    > But now I find it useful to avoid this step by directly including the
    > library's class files, which are located under $L/classes. What about this?


    Terrible idea, and the wrong way to do it.

    > If including the class files directly, where in the war [sic]

    file do they belong?

    They don't.

    Libraries belong in JAR files.

    RTFM.

    Really. You're doing it all ass-backwards.

    http://www.oracle.com/technetwork/java/javaee/documentation/tutorials-137605.html

    --
    Lew
    Lew, Nov 19, 2012
    #4
  5. Laura Schmidt

    Arne Vajhøj Guest

    On 11/18/2012 10:21 PM, Laura Schmidt wrote:
    > On 11/18/2012 06:01 PM, Arne Vajhøj wrote:
    >> On 11/18/2012 11:53 AM, Laura Schmidt wrote:
    >>> Within the produced war file, the class files of L were in the root
    >>> directory. I believe that the class files should be placed into the
    >>> WEB-INF/classes directory of the war file.
    >>>
    >>> However, this problem cannot be new and there must be a standard way to
    >>> do it. I would be glad if someone can tell me how to do it right.

    >>
    >> The war task has a nested lib element.
    >>
    >> There is an example at the bottom at:
    >> http://ant.apache.org/manual/Tasks/war.html
    >>
    >> Use that!

    >
    > If I use that I''ll have to create a jar file for the library every time
    > I make changes to it.


    You want to do that anyway.

    You could even say that if it is not in a jar then it is not a
    library.

    > Instead of the lib element I used a symbolic link
    > in the WEB-INF/lib directory of the project pointing to the library's
    > jar file. This is the way I always did it.


    That makes the war file tied to your PC.

    Not a good way.

    > But now I find it useful to avoid this step by directly including the
    > library's class files, which are located under $L/classes. What about this?


    Extracting class files out of libraries jar files is not good as
    it complicates updating and will confuse people working with it.

    > If including the class files directly, where in the war file do they
    > belong?


    The war task also has a nested classes element.

    It is all in the docs.

    Arne
    Arne Vajhøj, Nov 19, 2012
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Jessel
    Replies:
    2
    Views:
    435
    John C. Bollinger
    Nov 4, 2003
  2. Werner Butscher
    Replies:
    2
    Views:
    1,240
    Werner Butscher
    Aug 2, 2004
  3. ddog
    Replies:
    1
    Views:
    527
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Aug 12, 2007
  4. harryos

    ant doubt using war task

    harryos, Dec 3, 2008, in forum: Java
    Replies:
    0
    Views:
    295
    harryos
    Dec 3, 2008
  5. Thomas Kellerer

    Problem creating war file with warbler

    Thomas Kellerer, Mar 25, 2008, in forum: Ruby
    Replies:
    8
    Views:
    165
    Charles Oliver Nutter
    Apr 3, 2008
Loading...

Share This Page