RE: Still problems to create Ant task

From: DOMINGUEZ Felipe (Felipe.DOMINGUE..urocontrol.int)
Date: Mon Oct 16 2006 - 04:24:11 EDT

  • Next message: DOMINGUEZ Felipe: "FW: Still problems to create Ant task"

    Hi Andrus.

    I realized that it only works if I add the cayenne.jar to the $CLASSPATH
    outside of ant.

    Other wise cayenne cannot find the adapter, but the ant task always
    finds it.

    I have added a few lines to you example to instantiate the Adapter, and
    they never fail.

    Object obj= null;
    try{
            obj =
    Class.forName("org.apache.cayenne.dba.oracle.OracleAdapter")
                    .newInstance();
    }catch(Exception e){
            throw new BuildException(e);
    }

    I send an example attached.
    I assume you have cayenne.jar in your classpath.

    If you run ant in the AntExample folder it should work (in your
    environment should only complain about not been able to connect to the
    DB)

    If you execute the ClearClasspath batch file (or just remove cayenne.jar
    for your $CLASSPATH) and then run ant again, it would say that it cannot
    find the adapter.

    Is it there any way to avoid it. I would rather been able to fully
    configure the working environment from within ant.

    Thanks again for your help.

    Cheers

    Felipe

    -----Original Message-----
    From: Andrus Adamchik [mailto:andru..bjectstyle.org]
    Sent: Friday 13 October 2006 20:53
    To: cayenne-use..ncubator.apache.org
    Subject: Re: Still problems to create Ant task

    I just created a small test project and it seems to work just fine.
    The jar path includes cayenne.jar, task.jar and driver.jar.

    Andrus

    public class TestTask extends Task {

            protected File cayenneProject;

            public void setCayenneProject(File cayenneProject) {
                    this.cayenneProject = cayenneProject;
            }

            public void execute() throws BuildException {
                    Configuration c = new FileConfiguration(cayenneProject);
                    Configuration.initializeSharedConfiguration(c);

                    DataNode node = (DataNode)
    c.getDomain().getDataNodes().iterator()
                                    .next();
                    DataMap map = (DataMap)
    c.getDomain().getDataMaps().iterator().next();

                    DbGenerator gen = new DbGenerator(node.getAdapter(),
    map);
                    try {
                            gen.runGenerator(node.getDataSource());
                    } catch (Exception e) {
                            throw new BuildException(e);
                    }
            }
    }

    <project name="test" default="d">

            <path id="lib.path">
                    <fileset dir="lib" includes="*.jar" />
            </path>

            <target name="d">
                    <taskdef name="x" classname="test.TestTask"
    classpathref="lib.path"/>
                    <x cayenneProject="src/cayenne.xml"/>
            </target>
    </project>

    On Oct 13, 2006, at 1:40 PM, DOMINGUEZ Felipe wrote:

    > Hello.
    >
    > I am still having problems building an ant task that uses cayenne.
    >
    > I use the FileConfiguration class,
    >
    >
    >
    > FileConfiguration conf = new FileConfiguration("cayenne.xml");
    >
    > conf.addClassPath("pathToCayenneDir");
    >
    > Configuration.initializeSharedConfiguration(conf);
    >
    >
    >
    > but it throws a
    >
    > java.lang.ClassNotFoundException:
    > org.apache.cayenne.dba.hsqldb.HSQLDBAdapter
    >
    >
    >
    > in Configuration.initializeSharedConfiguration(conf);
    >
    >
    >
    >
    >
    > the class path use to run the ant task is OK, and I can even
    > instantiate
    > the class using
    >
    > Class.forName("org.apache.cayenne.dba.hsqldb.HSQLDBAdapter");
    >
    >
    >
    > can any body send and example or point me to a tutorial where I can
    > find
    > out what is going on.
    >
    > I did not find anything.
    >
    >
    >
    > cheers
    >
    > Felipe
    >
    >
    > ____
    >
    > This message and any files transmitted with it are legally
    > privileged and intended for the sole use of the individual(s) or
    > entity to whom they are addressed. If you are not the intended
    > recipient, please notify the sender by reply and delete the message
    > and any attachments from your system. Any unauthorised use or
    > disclosure of the content of this message is strictly prohibited
    > and may be unlawful.
    >
    > Nothing in this e-mail message amounts to a contractual or legal
    > commitment on the part of EUROCONTROL, unless it is confirmed by
    > appropriately signed hard copy.
    >
    > Any views expressed in this message are those of the sender.
    >

    ____

    This message and any files transmitted with it are legally privileged and intended for the sole use of the individual(s) or entity to whom they are addressed. If you are not the intended recipient, please notify the sender by reply and delete the message and any attachments from your system. Any unauthorised use or disclosure of the content of this message is strictly prohibited and may be unlawful.

    Nothing in this e-mail message amounts to a contractual or legal commitment on the part of EUROCONTROL, unless it is confirmed by appropriately signed hard copy.

    Any views expressed in this message are those of the sender.



    This archive was generated by hypermail 2.0.0 : Mon Oct 16 2006 - 04:24:46 EDT