You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Phillip Rhodes <rh...@yahoo.com> on 2005/12/13 05:27:52 UTC

Help with new ant task that uses spring

The problem is my ant task cannot seem to locate an xml file that is to 
be located in the classpath.  I have supplied the directory the xml file 
is in to the taskdef (the same classpath definition works on the java 
and junit tasks).  When I invoke the task, my task is found, but the 
spring config file (configured to read via the classpath) is not found.

I would really appreciate some scolding.  Thanks.

My taskdef is as follows:
        <taskdef name="authsum"
            
classname="org.authsum.configuration.ant.taskdefs.AuthSumProperty">
            <classpath>
                <path refid="springframework.classpath"/>
                <fileset file="../dbom/build/dbom.jar"/>
                <fileset file="../services/build/services.jar"/>
                    <!--  the configContext.xml file is in 
../services/src/conf -->
                <dirset dir="../services/src/conf"/>
                <!-- the following is to pick the log4j props -->
                <dirset dir="../src/conf"/>
                <fileset file="../anttask/build/anttask.jar"/>
            </classpath>
        </taskdef>      

BUILD FAILED
/home/rhodepc/configuration/tests/build.xml:97: 
org.springframework.beans.factory.BeanDefinitionStoreException: 
IOException parsing XML document from class path resource 
[configContext.xml]; nested exception is java.io.FileNotFoundException: 
class path resource [configContext.xml] cannot be opened because it does 
not exist

If you made it this far, thanks.  The project is a web-based java 
properties manager in which property values are "tagged" in order to use 
in grid like environments.  More info at
http://test.rhoderunner.com:8080/config/




---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: Help with new ant task that uses spring

Posted by Stefan Bodewig <bo...@apache.org>.
On Tue, 13 Dec 2005, Phillip Rhodes <rh...@yahoo.com> wrote:

> I thank you for responding, however, I can able to successfully use
> spring from within ant (using the java and junit tasks).

Even with fork="false"?

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: Help with new ant task that uses spring

Posted by Kev Jackson <ke...@it.fts-vn.com>.
Phillip Rhodes wrote:

> I thank you for responding, however, I can able to successfully use 
> spring from within ant (using the java and junit tasks).  My java and 
> junit tasks (which work) have the exact same classpath as my taskdef.  
> It seems that by having it in a taskdef does not allow for classpath 
> resources that are directories.  My other resources (spring jars, 
> custom pojo's) appear to be visible to the ant task.  Just not 
> directories in which resources are kept.
>
>
Ok then a workaround would be to put the confic.xml file into a jar and 
include the jar in your class path to ensure that what you say is 
actually true for all resources

Kev

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: Help with new ant task that uses spring

Posted by Phillip Rhodes <rh...@yahoo.com>.
I thank you for responding, however, I can able to successfully use 
spring from within ant (using the java and junit tasks).  My java and 
junit tasks (which work) have the exact same classpath as my taskdef.  
It seems that by having it in a taskdef does not allow for classpath 
resources that are directories.  My other resources (spring jars, custom 
pojo's) appear to be visible to the ant task.  Just not directories in 
which resources are kept.




Kev Jackson wrote:

>
>> My taskdef is as follows:
>>        <taskdef name="authsum"
>>            
>> classname="org.authsum.configuration.ant.taskdefs.AuthSumProperty">
>>            <classpath>
>>                <path refid="springframework.classpath"/>
>>                <fileset file="../dbom/build/dbom.jar"/>
>>                <fileset file="../services/build/services.jar"/>
>>                    <!--  the configContext.xml file is in 
>> ../services/src/conf -->
>>                <dirset dir="../services/src/conf"/>
>>                <!-- the following is to pick the log4j props -->
>>                <dirset dir="../src/conf"/>
>>                <fileset file="../anttask/build/anttask.jar"/>
>>            </classpath>
>>        </taskdef>     BUILD FAILED
>> /home/rhodepc/configuration/tests/build.xml:97: 
>> org.springframework.beans.factory.BeanDefinitionStoreException: 
>> IOException parsing XML document from class path resource 
>> [configContext.xml]; nested exception is 
>> java.io.FileNotFoundException: class path resource 
>> [configContext.xml] cannot be opened because it does not exist
>
>
> This is really more of a spring config issue than an ant issue from 
> what I can see from the stack trace.  I remember Spring being quite 
> awkward with respect to loading xml files from classpath, can you 
> build a basic unit test like so:
>
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
> import org.springframework.context.ApplicationContext;
> import 
> org.springframework.context.support.ClassPathXmlApplicationContext;
>
> import junit.framework.TestCase;
>
> public class BaseDAOTestCase extends TestCase {
>
>    protected final Log log = LogFactory.getLog(getClass());
>    protected final static ApplicationContext CTX;
>      static {
>        String[] paths = {"applicationContext.xml"};
>        CTX = new ClassPathXmlApplicationContext(paths);
>    }
>
>  public void testClasspath() {
>    assert(true);
>  }
> }
>
> basically this will remove ant completely from the equation and allow 
> you to focus on why Spring cannot resolve the config file.
>
> I have had problems in the past trying to run stuff like this from 
> within eclipse (as it has it's own ideas of classpath), so make sure 
> you do this from command line and make sure that CLASSPATH variable is 
> not set first, hope this helps
>
> Kev
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: Help with new ant task that uses spring

Posted by Kev Jackson <ke...@it.fts-vn.com>.
> My taskdef is as follows:
>        <taskdef name="authsum"
>            
> classname="org.authsum.configuration.ant.taskdefs.AuthSumProperty">
>            <classpath>
>                <path refid="springframework.classpath"/>
>                <fileset file="../dbom/build/dbom.jar"/>
>                <fileset file="../services/build/services.jar"/>
>                    <!--  the configContext.xml file is in 
> ../services/src/conf -->
>                <dirset dir="../services/src/conf"/>
>                <!-- the following is to pick the log4j props -->
>                <dirset dir="../src/conf"/>
>                <fileset file="../anttask/build/anttask.jar"/>
>            </classpath>
>        </taskdef>     
> BUILD FAILED
> /home/rhodepc/configuration/tests/build.xml:97: 
> org.springframework.beans.factory.BeanDefinitionStoreException: 
> IOException parsing XML document from class path resource 
> [configContext.xml]; nested exception is 
> java.io.FileNotFoundException: class path resource [configContext.xml] 
> cannot be opened because it does not exist

This is really more of a spring config issue than an ant issue from what 
I can see from the stack trace.  I remember Spring being quite awkward 
with respect to loading xml files from classpath, can you build a basic 
unit test like so:

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import junit.framework.TestCase;

public class BaseDAOTestCase extends TestCase {

    protected final Log log = LogFactory.getLog(getClass());
    protected final static ApplicationContext CTX;
   
    static {
        String[] paths = {"applicationContext.xml"};
        CTX = new ClassPathXmlApplicationContext(paths);
    }

  public void testClasspath() {
    assert(true);
  }
}

basically this will remove ant completely from the equation and allow 
you to focus on why Spring cannot resolve the config file.

I have had problems in the past trying to run stuff like this from 
within eclipse (as it has it's own ideas of classpath), so make sure you 
do this from command line and make sure that CLASSPATH variable is not 
set first, hope this helps

Kev

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: Help with new ant task that uses spring

Posted by Phillip Rhodes <rh...@yahoo.com>.
Found the answer to my question with this post:

http://www.ant-tasks.com/msg/9124.html


I ended up swapping out the AntClassLoader as directed in this post.


Phillip Rhodes wrote:

> The problem is my ant task cannot seem to locate an xml file that is 
> to be located in the classpath.  I have supplied the directory the xml 
> file is in to the taskdef (the same classpath definition works on the 
> java and junit tasks).  When I invoke the task, my task is found, but 
> the spring config file (configured to read via the classpath) is not 
> found.
>
> I would really appreciate some scolding.  Thanks.
>
> My taskdef is as follows:
>        <taskdef name="authsum"
>            
> classname="org.authsum.configuration.ant.taskdefs.AuthSumProperty">
>            <classpath>
>                <path refid="springframework.classpath"/>
>                <fileset file="../dbom/build/dbom.jar"/>
>                <fileset file="../services/build/services.jar"/>
>                    <!--  the configContext.xml file is in 
> ../services/src/conf -->
>                <dirset dir="../services/src/conf"/>
>                <!-- the following is to pick the log4j props -->
>                <dirset dir="../src/conf"/>
>                <fileset file="../anttask/build/anttask.jar"/>
>            </classpath>
>        </taskdef>     
> BUILD FAILED
> /home/rhodepc/configuration/tests/build.xml:97: 
> org.springframework.beans.factory.BeanDefinitionStoreException: 
> IOException parsing XML document from class path resource 
> [configContext.xml]; nested exception is 
> java.io.FileNotFoundException: class path resource [configContext.xml] 
> cannot be opened because it does not exist
>
> If you made it this far, thanks.  The project is a web-based java 
> properties manager in which property values are "tagged" in order to 
> use in grid like environments.  More info at
> http://test.rhoderunner.com:8080/config/
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: Help with new ant task that uses spring

Posted by Stefan Bodewig <bo...@apache.org>.
On Mon, 12 Dec 2005, Phillip Rhodes <rh...@yahoo.com> wrote:

> The problem is my ant task cannot seem to locate an xml file that is
> to be located in the classpath.  I have supplied the directory the
> xml file is in to the taskdef (the same classpath definition works
> on the java and junit tasks).

Can your task be loaded using the system CLASSPATH as well?  If so, it
will be loaded from there and your <classpath> will be ignored (since
your class doesn't know about it).

If you run "ant -debug" you should see which classloader is loading
which class.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org