You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by tek1 <te...@pobox.com> on 2002/04/06 14:48:03 UTC

custom ant task can't find classpath

i'm having a problem with one my taskdefs.

the custom task that i've created is basically calling a .class located in 
a .jar and passing it some parameters.

the part of the build.xml file calling my custom task basically looks like this.


     <target name="modifyIt">

         <taskdef name="mytask" classname="com.mycom.MyCustomTask">

             <classpath>
                  <pathelement location="/dev/anttasks/mytasks.jar"/>
             </classpath>

         </taskdef>



         <mytask param1="abc" helperJar="/java/helper/123/helper.jar"/>


     </target>
</project>


my custom task is calling the Help.class in the helper.jar.

the command line that is constructed by my custom task ("mytask") and that 
is executed is:

(i'm using windows2000, so all the paths are converted appropriately)

c:\java\j2se\sun\131_02\bin\java.exe -classpath 
c:\java\helper\123\helper.jar Help abc


if i type in this command at the dos prompt, it works.  however, when my 
ant script runs, ant complains that it could not find Help and that i 
should check to see if i have it in my classpath.  i'm getting the same 
error when i try to run my script from within netbeans also...

any advice is greatly appreciated.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: custom ant task can't find classpath

Posted by tek1 <te...@pobox.com>.
looks like:

ExecuteJava execJava = new ExecuteJava();
execJava.setClasspath( helperJarFile );

did the trick.  thank you.

i missed the "setClasspath()" method.  perhaps it's just me, but that 
method seems better suited for the CommandlineJava class...

anyway, the ant task works (at the command line), but i'm now getting the 
following when i try to run the task from within netbeans:


org.netbeans.core.execution.ExitSecurityException
         at 
org.netbeans.core.execution.TopSecurityManager.checkExitImpl(TopSecurityManager.java:95)
         at 
org.netbeans.core.execution.TopSecurityManager$PrivilegedCheck.run(TopSecurityManager.java:458)
         at java.security.AccessController.doPrivileged(Native Method)
         at 
org.netbeans.core.execution.TopSecurityManager$PrivilegedCheck.check(TopSecurityManager.java:483)
         at 
org.netbeans.core.execution.TopSecurityManager$PrivilegedCheck.checkExit(TopSecurityManager.java:471)
         at 
org.netbeans.core.execution.TopSecurityManager.checkExit(TopSecurityManager.java:78)
         at java.lang.Runtime.exit(Runtime.java:91)
         at java.lang.System.exit(System.java:701)
         at MyJavaClass.main(Unknown Source)
         at java.lang.reflect.Method.invoke(Native Method)
         at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:124)
         at com.vizionari.ant.obfuscator.RetroGuardTask.execCmdLine(Unknown Source)
         at com.vizionari.ant.obfuscator.RetroGuardTask.execute(Unknown Source)
         at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:104)
         at org.apache.tools.ant.Task.perform(Task.java:217)
         at org.apache.tools.ant.Target.execute(Target.java:184)
         at org.apache.tools.ant.Target.performTasks(Target.java:202)
         at org.apache.tools.ant.Project.executeTarget(Project.java:601)
         at org.apache.tools.ant.Project.executeTargets(Project.java:560)
         at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:277)
         at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:118)


i think that this is more of a netbeans issue than ant, so no replies 
necessary, but if you also use ant with netbeans and have experienced this, 
i'd appreciate any hints.

does it mean that the java .class is trying to call something like 
System.exit(0) and netbeans won't permit it b/c if it does, netbeans also 
will exit?  for those familiar with ant, does this mean that i have to 
"fork the vm" when i execute my java .class?

thank you.





At 12:59 02/04/09 +0900, you wrote:
>At 09:40 02/04/09 +1000, you wrote:
>
>>Hi,
>>
>>It's kinda hard to figure out what's going wrong without seeing your code.
>>Using ExecuteJava is pretty straight-forward, though - you should be doing
>>something like this in your task:
>>
>>public void execute()
>>{
>>     Path classpath = new Path( getProject() );
>>     classpath.setLocation( helperJarFile );
>
>i tried:
>
>Commandline cmdline = new Commandline();
>
>Path p = cmdline.createClasspath( getProject() );
>p.setLocation( helperJarFile );
>
>  this, but when i print out the parameters that are being used for the 
> command line, the classpath appears to be null.  as a result, i'm setting 
> the classpath by doing the following:
>
>cmdline.createArgument().setValue("-classpath");
>cmdline.createArgument().setValue(absolutePathToJarFile);
>
>everything else is the same.  i will try your suggestion for setting the 
>classpath.
>
>thank you.
>
>
>
>>     Commandline cmdline = new Commandline();
>>     cmdline.setExecutable( "Help" );
>>     cmdline.createArgument().setValue( param1 );
>>
>>     ExecuteJava exe = new ExecuteJava();
>>     exe.setCommandline( cmdline );
>>     exe.setClasspath( classpath );
>>
>>     exe.execute( getProject() );
>>}
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: custom ant task can't find classpath

Posted by tek1 <te...@pobox.com>.
At 09:40 02/04/09 +1000, you wrote:

>Hi,
>
>It's kinda hard to figure out what's going wrong without seeing your code.
>Using ExecuteJava is pretty straight-forward, though - you should be doing
>something like this in your task:
>
>public void execute()
>{
>     Path classpath = new Path( getProject() );
>     classpath.setLocation( helperJarFile );

i tried:

Commandline cmdline = new Commandline();

Path p = cmdline.createClasspath( getProject() );
p.setLocation( helperJarFile );

  this, but when i print out the parameters that are being used for the 
command line, the classpath appears to be null.  as a result, i'm setting 
the classpath by doing the following:

cmdline.createArgument().setValue("-classpath");
cmdline.createArgument().setValue(absolutePathToJarFile);

everything else is the same.  i will try your suggestion for setting the 
classpath.

thank you.



>     Commandline cmdline = new Commandline();
>     cmdline.setExecutable( "Help" );
>     cmdline.createArgument().setValue( param1 );
>
>     ExecuteJava exe = new ExecuteJava();
>     exe.setCommandline( cmdline );
>     exe.setClasspath( classpath );
>
>     exe.execute( getProject() );
>}


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: custom ant task can't find classpath

Posted by Adam Murdoch <ad...@apache.org>.
Hi,

It's kinda hard to figure out what's going wrong without seeing your code.  
Using ExecuteJava is pretty straight-forward, though - you should be doing 
something like this in your task:

public void execute()
{
    Path classpath = new Path( getProject() );
    classpath.setLocation( helperJarFile );

    Commandline cmdline = new Commandline();
    cmdline.setExecutable( "Help" );
    cmdline.createArgument().setValue( param1 );

    ExecuteJava exe = new ExecuteJava();
    exe.setCommandline( cmdline );
    exe.setClasspath( classpath );

    exe.execute( getProject() );
}

On Tue, 9 Apr 2002 09:15, tek1 wrote:
> ExecuteJava
>
>
> thanks...
>
> At 17:22 02/04/07 +1000, you wrote:
> >On Sat, 6 Apr 2002 22:48, tek1 wrote:
> > > my custom task is calling the Help.class in the helper.jar.
> >
> >How does your task call the Help class?  Reflection?  ExecuteJava? 
> > Execute? Runtime.exec()?
> >

-- 
Adam

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: custom ant task can't find classpath

Posted by tek1 <te...@pobox.com>.
ExecuteJava


thanks...



At 17:22 02/04/07 +1000, you wrote:
>On Sat, 6 Apr 2002 22:48, tek1 wrote:
> >
> > my custom task is calling the Help.class in the helper.jar.
> >
>
>How does your task call the Help class?  Reflection?  ExecuteJava?  Execute?
>Runtime.exec()?
>
>
>Adam
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Can't put optional tasks jar out of ant/lib

Posted by Stefan Bodewig <bo...@apache.org>.
On Sat, 6 Apr 2002, Nicola Ken Barozzi <ni...@apache.org> wrote:

> Any clues?

<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6606>

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Can't put optional tasks jar out of ant/lib

Posted by Nicola Ken Barozzi <ni...@apache.org>.
I'm trying to use the JDepend optional task without having to put the
jdepend.jar in the ant/lib dir.

So I have (yesterday's CVS version of jar):

./tools/ant/lib/ant.jar
./tools/ant/lib/optional.jar

./tools/tmp/tasks.properties (containing the task definition)

./tools/other/lib/jdepend.jar

I write:

    <!-- define the tasks found in cents -->
    <taskdef file="./tools/tmp/tasks.properties">
     <classpath>
      <fileset dir="./tools">
        <include name="**/*.jar"/>
      </fileset>
     </classpath>
    </taskdef>

But in verbose mode it says:

  [taskdef] Loading definitions from file
C:\jbprojects\jakarta-poi\tools\tmp\ta
sks.properties

BUILD FAILED
C:\jbprojects\jakarta-poi\build.xml:68: taskdef class
org.apache.tools.ant.taskd
efs.optional.jdepend.JDependTask cannot be found
        at
org.apache.tools.ant.taskdefs.Definer.addDefinition(Definer.java:189)

        at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:167)
        at org.apache.tools.ant.Task.perform(Task.java:313)
        at org.apache.tools.ant.Target.execute(Target.java:309)
        at org.apache.tools.ant.Target.performTasks(Target.java:334)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1176)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1118)
        at org.apache.tools.ant.Main.runBuild(Main.java:573)
        at org.apache.tools.ant.Main.start(Main.java:179)
        at org.apache.tools.ant.Main.main(Main.java:201)
--- Nested Exception ---
java.lang.NoClassDefFoundError: jdepend/xmlui/JDepend
        at java.lang.Class.getDeclaredConstructors0(Native Method)
        at java.lang.Class.privateGetDeclaredConstructors(Class.java:1576)
        at java.lang.Class.getDeclaredConstructors(Class.java:1140)
        at
org.apache.tools.ant.AntClassLoader.initializeClass(AntClassLoader.ja
va:478)
        at
org.apache.tools.ant.taskdefs.Definer.addDefinition(Definer.java:180)

        at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:167)
        at org.apache.tools.ant.Task.perform(Task.java:313)
        at org.apache.tools.ant.Target.execute(Target.java:309)
        at org.apache.tools.ant.Target.performTasks(Target.java:334)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1176)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1118)
        at org.apache.tools.ant.Main.runBuild(Main.java:573)
        at org.apache.tools.ant.Main.start(Main.java:179)
        at org.apache.tools.ant.Main.main(Main.java:201)

If I put jdepend.jar in ant/lib it works but I don't want to do it.
Also changeing the script is not an option because some use build.xml
directly with ant called via java.

Any clues?

Thanks in advance :-)

--
Nicola Ken Barozzi                   nicolaken@apache.org
            - verba volant, scripta manent -
   (discussions get forgotten, just code remains)
---------------------------------------------------------------------


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: custom ant task can't find classpath

Posted by Adam Murdoch <ad...@apache.org>.
On Sat, 6 Apr 2002 22:48, tek1 wrote:
>
> my custom task is calling the Help.class in the helper.jar.
>

How does your task call the Help class?  Reflection?  ExecuteJava?  Execute?  
Runtime.exec()?


Adam

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>