You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by da...@cartridgeorder.com on 2011/01/19 20:30:35 UTC

Execution classpath question for taskdef

Hi,

I'm using Ant 1.8.  I have created a custom task, but I need to include a jar file in the classpath when this task is exected.  How do I include such a jar file?  I'm using Ant 1.8.  Here is the definition of the task ...

<target name="Selenium4" depends="checkout-selenium-tests">
        <echo message="selenium paths ..." />
        <echo message="${selenium-lib}" />
        <echo message="${selenium.jar.path}" />
        <taskdef name="SeleniumHTMLClient" classname="com.criticalmass.util.ant.SeleniumRunner" classpath="${selenium-lib}:${selenium.jar.path}">
                <classpath refid="selenium-classpath-ref" />
        </taskdef>

        <property name="results" location="${selenium.base.test.dir}/Results.html" />
        <property name="base.test.dir" value="${lvcva.checkout.dir}/${selenium.vegas.test.root}" />

        <SeleniumHTMLClient results="${results}"
                            appendResults="true"
                            verbose="true"
                            showPassedTests="false"
                            excludeHeaderAndFooter="true"
                            multithread="true"
                            emailTo="${selenium.email.to}"
                            emailFrom="${selenium.email.from}"
                            emailSubject="${selenium.email.subject}"
                            emailHost="${selenium.email.host}">

                <Host value="${selenium.windows.host.value}" port="${selenium.windows.host.port}">
                        <Browser value="*chrome" />
                        <Browser value="*iehta" />
                </Host>

                <TestSuite baseurl="${selenium.vlv.baseurl}">
                        <fileset dir="${base.test.dir}/${selenium.vlv.test.dir}">
                                <include name="**\*.html" />
                        </fileset>
                </TestSuite>
        </SeleniumHTMLClient>

        <concat destfile="${selenium.base.test.dir}/Results2.html">
                <header file="${selenium.base.test.dir}/selenium-header.html" />
                <fileset dir="${selenium.base.test.dir}" includes="Results.html">
                </fileset>
                <footer file="${selenium.base.test.dir}/selenium-footer.html" />
        </concat>

        <delete file="${results}"/>
</target>

I have discovered that the "classpath" and "claspathref" elements that are part of the taskdef are not used during run time, so I am grateful for anyone to tell me how to include classes when the task is actually executed. - Dave

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


Re: Execution classpath question for taskdef

Posted by Antoine Levy-Lambert <an...@gmx.de>.
On 1/19/11 3:26 PM, dave.alvarado@cartridgeorder.com wrote:
> Let me ask this clarification question before answering yours ...
>
> 1. The taskdef "classpath" attribute is NOT what is used when the taskdef is actually executed.  Correct?
Wrong, the classpath nested element or attribute is used. I notice you
are using both the classpath attribute and the nested element.

  <taskdef name="SeleniumHTMLClient" classname="com.criticalmass.util.ant.SeleniumRunner" classpath="${selenium-lib}:${selenium.jar.path}">
                <classpath refid="selenium-classpath-ref" />
        </taskdef>


You should use only one of the nested element or the attribute.

If you use the attribute, the proper path separator for your operating
system should be used.

this ${selenium-lib}:${selenium.jar.path} is only legit on UNIX.

Better is to write ${path.separator} instead of ":"   

Also if "${selenium-lib}" is a directory I am not sure it is going to include all the jars in this directory

maybe you want to define your path like that

<path id="selenium-classpath-ref">
  <fileset dir="${selenium-lib}">
    <include name="*.jar"/>
  </fileset> 
  <pathelement location="${selenium.jar.path}"/>
</path>

and your taskdef like that :

  <taskdef name="SeleniumHTMLClient" classname="com.criticalmass.util.ant.SeleniumRunner" >
                <classpath refid="selenium-classpath-ref" />
        </taskdef>



Regards,

Antoine

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


Re: Execution classpath question for taskdef

Posted by da...@cartridgeorder.com.
Let me ask this clarification question before answering yours ...

1. The taskdef "classpath" attribute is NOT what is used when the taskdef is actually executed.  Correct?

The output of what I get from running my custom task is below.  Note that the NoClassDefFoundError is complaining about a class that is in the "/opt/LVCVA/lvcva_tomcat/sandboxes/lvcva-dev-build/common/selenium-server.jar" jar file, and I have verified that this file exists.

Selenium4:
     [echo] selenium paths ...
     [echo] /opt/LVCVA/lvcva_tomcat/sandboxes/lvcva-dev-build/common/selenium-server.jar
     [echo] /opt/LVCVA/lvcva_tomcat/sandboxes/lvcva-dev-build/common/CmSeleniumUtils.jar
[SeleniumHTMLClient] added test suite.

BUILD FAILED
/opt/LVCVA/lvcva_tomcat/build.xml:746: java.lang.NoClassDefFoundError: com/thoughtworks/selenium/SeleniumException
        at com.criticalmass.util.ant.SeleniumRunner.execute(SeleniumRunner.java:158)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:390)
        at org.apache.tools.ant.Target.performTasks(Target.java:411)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1397)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1366)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1249)
        at org.apache.tools.ant.Main.runBuild(Main.java:801)
        at org.apache.tools.ant.Main.startAnt(Main.java:218)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: java.lang.ClassNotFoundException: com.thoughtworks.selenium.SeleniumException
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
        ... 18 more

So my question remains, how do I set the classpath for when my custom task "SeleniumHTMLClient" is actually executed?  Thanks, - Dave






>  -------Original Message-------
>  From: Michael Ludwig <mi...@gmx.de>
>  To: user@ant.apache.org
>  Subject: Re: Execution classpath question for taskdef
>  Sent: Jan 19 '11 13:54
>  
>  dave.alvarado@cartridgeorder.com schrieb am 19.01.2011 um 13:30 (-0600):
>  
>  > I have discovered that the "classpath" and "claspathref" elements that
>  > are part of the taskdef are not used during run time
>  
>  Are you sure? How did you discover that?
>  
>  There was another thread today where the same issue arose:
>  
>    Mail task with mail.jar & activation.jar out of lib folder
>  
>    r L 19.01.11 10:31+0100 Patrick Martin    57 Mail task […]
>      L 19.01.11 11:19+0100 Patrick Martin    87 ├─>
>      F 19.01.11 13:51+0100 Michael Ludwig    75 └─>
>  
>  --
>  Michael Ludwig
>  
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>  For additional commands, e-mail: user-help@ant.apache.org
>  
>  

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


Re: Execution classpath question for taskdef

Posted by tstrall <te...@orbitz.com>.
I would concur that with Ant 1.8 the classpath which is being used in the
taskdef definition does not seem to be the same as the classpath used for
executing the task later.

In my case the taskdef is:

<taskdef classname="com.orbitz.insurance.engine.taskdefs.RebuildRulesTask"
name="rebuild-rulebase">
<classpath>
<path refid="classpath.build">
<pathelement location="${dir.compile}">
</pathelement></path></classpath>
</taskdef>

But when the task is called it returns the error:

java.lang.ClassNotFoundException:
com.orbitz.insurance.engine.services.impl.DroolsInsuranceServices

Both com.orbitz.insurance.engine.taskdefs.RebuildRulesTask and
com.orbitz.insurance.engine.services.impl.DroolsInsuranceServices
are in the same place on the classpath.

This worked with Ant 1.7. Any help would be appreciated.

-- 
View this message in context: http://ant.1045680.n5.nabble.com/Execution-classpath-question-for-taskdef-tp3348395p3396187.html
Sent from the Ant - Users mailing list archive at Nabble.com.

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


Re: Execution classpath question for taskdef

Posted by Antoine Levy-Lambert <an...@gmx.de>.
On 1/20/11 5:27 PM, dave.alvarado@cartridgeorder.com wrote:
> Thanks for this recommendation.  A couple of follow up questions ...
>
> 1 If I add the classloader task to my custom task, does that classloader take precedence over the classes loaded by ${ANT_HOME}/lib ?
> 2. How do I add the classloader task to my custom task?  My custom task resembles ...
No, you probably do not need this classloader task for selenium.
> <target name="Selenium4" depends="build-cm-selenium,checkout-selenium-tests">
>         <echo message="selenium paths ..." />
>         <echo message="${selenium-lib}" />
>         <echo message="${selenium.jar.path}" />
>         <taskdef name="SeleniumHTMLClient" classname="com.criticalmass.util.ant.SeleniumRunner" classpath="${selenium-lib}:${selenium.j
> ar.path}">                <classpath refid="selenium-classpath-ref" />
>         </taskdef>
You should probably choose between the classpath attribute or the
classpath nested element.
Make sure that the classpath that you use contains all the jars that you
need
you can add a line
<echo>selenium-classpath-ref=${toString:selenium-classpath-ref}</echo>

Antoine
>   
>
>
> Thanks, - Dave
>
>


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


Re: Execution classpath question for taskdef

Posted by da...@cartridgeorder.com.
Thanks for this recommendation.  A couple of follow up questions ...

1 If I add the classloader task to my custom task, does that classloader take precedence over the classes loaded by ${ANT_HOME}/lib ?
2. How do I add the classloader task to my custom task?  My custom task resembles ...

<target name="Selenium4" depends="build-cm-selenium,checkout-selenium-tests">
        <echo message="selenium paths ..." />
        <echo message="${selenium-lib}" />
        <echo message="${selenium.jar.path}" />
        <taskdef name="SeleniumHTMLClient" classname="com.criticalmass.util.ant.SeleniumRunner" classpath="${selenium-lib}:${selenium.j
ar.path}">                <classpath refid="selenium-classpath-ref" />
        </taskdef>

        <property name="results" location="${selenium.base.test.dir}/Results.html" />
        <property name="base.test.dir" value="${lvcva.checkout.dir}/${selenium.vegas.test.root}" />

        <SeleniumHTMLClient results="${results}"
                            appendResults="true"
                            verbose="true"
                            showPassedTests="false"
                            excludeHeaderAndFooter="true"
                            multithread="true"
                            emailTo="${selenium.email.to}"
                            emailFrom="${selenium.email.from}"
                            emailSubject="${selenium.email.subject}"
                            emailHost="${selenium.email.host}">

                <Host value="${selenium.windows.host.value}" port="${selenium.windows.host.port}">
                        <Browser value="*chrome" />
                        <Browser value="*iehta" />
                </Host>

                <TestSuite baseurl="${selenium.vlv.baseurl}">
                        <fileset dir="${base.test.dir}/${selenium.vlv.test.dir}">
                                <include name="**\*.html" />
                        </fileset>
                </TestSuite>
        </SeleniumHTMLClient>

        <concat destfile="${selenium.base.test.dir}/Results2.html">
                <header file="${selenium.base.test.dir}/selenium-header.html" />
                <fileset dir="${selenium.base.test.dir}" includes="Results.html">
                </fileset>
                <footer file="${selenium.base.test.dir}/selenium-footer.html" />
        </concat>

        <delete file="${results}"/>
</target>


Thanks, - Dave



>  -------Original Message-------
>  From: Antoine Levy-Lambert <an...@gmx.de>
>  To: Ant Users List <us...@ant.apache.org>
>  Subject: Re: Execution classpath question for taskdef
>  Sent: Jan 19 '11 17:58
>  
>  On 1/19/11 2:54 PM, Michael Ludwig wrote:
>  >
>  > There was another thread today where the same issue arose:
>  >
>  >   Mail task with mail.jar & activation.jar out of lib folder
>  >
>  >   r L 19.01.11 10:31+0100 Patrick Martin    57 Mail task […]
>  >     L 19.01.11 11:19+0100 Patrick Martin    87 ├─>
>  >     F 19.01.11 13:51+0100 Michael Ludwig    75 └─>
>  The classpath attribute or nested element of taskdef works but cannot
>  solve the case of some classes loaded by factories of the JVM (JDBC
>  drivers, mail.jar, activation.jar).
>  These classes have to be either in the ant startup environment. See
>  http://ant.apache.org/manual/running.html#libs
>  
>  Or the classloader task must be used to add the jars to the classloader
>  so that ant classes can access them.
>  
>  As Peter Reilly wrote the URL from which this classloader task can be
>  downloaded is :
>  
>  http://enitsys.sourceforge.net/ant-classloadertask/
>  
>  
>  
>  Regards,
>  
>  Antoine
>  
>  
>  
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>  For additional commands, e-mail: user-help@ant.apache.org
>  
>  

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


Re: Execution classpath question for taskdef

Posted by Antoine Levy-Lambert <an...@gmx.de>.
On 1/19/11 2:54 PM, Michael Ludwig wrote:
>
> There was another thread today where the same issue arose:
>
>   Mail task with mail.jar & activation.jar out of lib folder
>
>   r L 19.01.11 10:31+0100 Patrick Martin    57 Mail task […]
>     L 19.01.11 11:19+0100 Patrick Martin    87 ├─>
>     F 19.01.11 13:51+0100 Michael Ludwig    75 └─>
The classpath attribute or nested element of taskdef works but cannot
solve the case of some classes loaded by factories of the JVM (JDBC
drivers, mail.jar, activation.jar).
These classes have to be either in the ant startup environment. See
http://ant.apache.org/manual/running.html#libs

Or the classloader task must be used to add the jars to the classloader
so that ant classes can access them.

As Peter Reilly wrote the URL from which this classloader task can be
downloaded is :

http://enitsys.sourceforge.net/ant-classloadertask/



Regards,

Antoine



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


Re: Execution classpath question for taskdef

Posted by Michael Ludwig <mi...@gmx.de>.
dave.alvarado@cartridgeorder.com schrieb am 19.01.2011 um 13:30 (-0600):

> I have discovered that the "classpath" and "claspathref" elements that
> are part of the taskdef are not used during run time

Are you sure? How did you discover that?

There was another thread today where the same issue arose:

  Mail task with mail.jar & activation.jar out of lib folder

  r L 19.01.11 10:31+0100 Patrick Martin    57 Mail task […]
    L 19.01.11 11:19+0100 Patrick Martin    87 ├─>
    F 19.01.11 13:51+0100 Michael Ludwig    75 └─>

-- 
Michael Ludwig

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