You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by bool <ma...@yahoo.co.uk> on 2011/02/15 10:29:38 UTC

project.createTask() not working with ant-1.8.2

createTask() method is throwing the following error with ant-1.8.2 while it
works perfectly with Ant 1.7.1.

import org.apache.tools.ant.taskdefs.Delete;
Delete delete = (Delete) myProject.createTask("Delete"); 


jar:file:/myant/ant-1.8.2/lib/ant.jar!/org/apache/tools/ant/antlib.xml:37:
Problem: failed to create task or type componentdef
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.


I tried to remove all componentdef stuff from
org/apache/tools/ant/antlib.xml and then it started working again. 

Kindly let me know if there is a proper solution to this. And why this is
not working for me.
-- 
View this message in context: http://ant.1045680.n5.nabble.com/project-createTask-not-working-with-ant-1-8-2-tp3385716p3385716.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: project.createTask() not working with ant-1.8.2

Posted by bool <ma...@yahoo.co.uk>.
>> You shouldn't create a new Project object

Is there any reason? It was working perfectly fine with 1.7.1 version
-- 
View this message in context: http://ant.1045680.n5.nabble.com/project-createTask-not-working-with-ant-1-8-2-tp3385716p3386108.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: project.createTask() not working with ant-1.8.2

Posted by Vimil Saju <vi...@yahoo.com>.
>     /**
>      * Executes the desObfuscate task.
>      */
>     @Override
>     public void execute() throws BuildException
>     {
>         myProject = new Project();
> 
>         // Create ANT tasks
>         Task delete = (Delete)
> myProject.createTask(DELETE_TASK);
> 
>     }
> }

You shouldn't create a new Project object, You should call the getProject() method to get a reference to the project object under which the obfuscate task is defined.


 
____________________________________________________________________________________
Never miss an email again!
Yahoo! Toolbar alerts you the instant new Mail arrives.
http://tools.search.yahoo.com/toolbar/features/mail/

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


Re: project.createTask() not working with ant-1.8.2

Posted by Mohan <mo...@gmail.com>.
I'm attaching a sample code to reproduce the issue mentioned above.  Could
you please suggest a solution for this issue:

The build.xml file :
============================
<?xml version="1.0" encoding="UTF-8"?>
<project name="Base" default="compile" basedir=".">
    <description> Build file </description>

    <property environment="env"/>

    <!-- Compile everything -->
    <target name="compile"
        description="Test the creation of Task ">
        <echo>${ant.version}</echo>
        <taskdef name="checkTask"
            classname="Obfuscate"
            classpath="/u/chittelk/"/>
        <checkTask />
    </target>
</project>

===================================

Java file:

===================================
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.Delete;
import org.apache.tools.ant.types.FileSet;

public class Obfuscate extends Task
{
    private Project myProject;
    /**
     * ANT task name for Delete.
     */
    private static final String DELETE_TASK = "Delete";

    /**
     * Executes the desObfuscate task.
     */
    @Override
    public void execute() throws BuildException
    {
        myProject = new Project();

        // Create ANT tasks
        Task delete = (Delete) myProject.createTask(DELETE_TASK);

    }
}
=====================================================

Command invocation using ANT 1.8.2:

========================================
$> /prod/tools/infra/apache/ant-1.8.2/bin/ant compile
Buildfile: /u/chittelk/build.xml

compile:
     [echo] Apache Ant(TM) version 1.8.2 compiled on December 20 2010

BUILD FAILED
/u/chittelk/build.xml:16: The following error occurred while executing this
line:
jar:file:/prod/tools/infra/apache/ant-1.8.2/lib/ant.jar!/org/apache/tools/ant/antlib.xml:37:
Problem: failed to create task or type componentdef
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.


Total time: 0 seconds
========================================

Command invocation using ANT 1.7.1:
=========================================
$> /prod/tools/infra/apache/ant-1.7.1/bin/ant compile
Buildfile: build.xml

compile:
     [echo] Apache Ant version 1.7.1 compiled on June 27 2008

BUILD SUCCESSFUL
Total time: 0 seconds
========================================


-- 
View this message in context: http://ant.1045680.n5.nabble.com/project-createTask-not-working-with-ant-1-8-2-tp3385716p3385725.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: project.createTask() not working with ant-1.8.2

Posted by Mohan <mo...@gmail.com>.
I'm also attaching the stack trace of the error produced by the "-v" option,
if it helps :)

$> /prod/tools/infra/apache/ant-1.8.2/bin/ant compile -v
Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Trying the default build file: build.xml
Buildfile: /u/chittelk/build.xml
Detected Java version: 1.6 in: /usr/local/java/jdk1.6.0.21/jre
Detected OS: SunOS
parsing buildfile /u/chittelk/build.xml with URI =
file:/u/chittelk/build.xml
Project base dir set to: /u/chittelk
parsing buildfile
jar:file:/prod/tools/infra/apache/ant-1.8.2/lib/ant.jar!/org/apache/tools/ant/antlib.xml
with URI =
jar:file:/prod/tools/infra/apache/ant-1.8.2/lib/ant.jar!/org/apache/tools/ant/antlib.xml
from a zip file
 [property] Loading Environment env.
Build sequence for target(s) `compile' is [compile]
Complete build sequence is [compile, ]

compile:
     [echo] Apache Ant(TM) version 1.8.2 compiled on December 20 2010
     [echo] /prod/tools/infra/apache/ant-1.8.2

BUILD FAILED
/u/chittelk/build.xml:17: The following error occurred while executing this
line:
jar:file:/prod/tools/infra/apache/ant-1.8.2/lib/ant.jar!/org/apache/tools/ant/antlib.xml:37:
Problem: failed to create task or type componentdef
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

        at
org.apache.tools.ant.UnknownElement.getNotFoundException(UnknownElement.java:487)
        at
org.apache.tools.ant.UnknownElement.makeObject(UnknownElement.java:419)
        at
org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:163)
        at org.apache.tools.ant.taskdefs.Antlib.execute(Antlib.java:162)
        at
org.apache.tools.ant.taskdefs.Definer.loadAntlib(Definer.java:443)
        at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:292)
        at
org.apache.tools.ant.ComponentHelper.checkNamespace(ComponentHelper.java:869)
        at
org.apache.tools.ant.ComponentHelper.getDefinition(ComponentHelper.java:308)
        at
org.apache.tools.ant.ComponentHelper.getComponentClass(ComponentHelper.java:298)
        at
org.apache.tools.ant.ComponentHelper.createNewTask(ComponentHelper.java:547)
        at
org.apache.tools.ant.ComponentHelper.createTask(ComponentHelper.java:524)
        at org.apache.tools.ant.Project.createTask(Project.java:1179)
        at Obfuscate.execute(Obfuscate.java:29)
        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:1399)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
        at
org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
        at org.apache.tools.ant.Main.runBuild(Main.java:809)
        at org.apache.tools.ant.Main.startAnt(Main.java:217)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

Total time: 0 seconds

-- 
View this message in context: http://ant.1045680.n5.nabble.com/project-createTask-not-working-with-ant-1-8-2-tp3385716p3385995.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: project.createTask() not working with ant-1.8.2

Posted by bool <ma...@yahoo.co.uk>.
Also we see failures when we donot have "force" attribute set for overriding
read only files. So we should be using 1.8.2 version only right as this
feature is present only in this version.....???
-- 
View this message in context: http://ant.1045680.n5.nabble.com/project-createTask-not-working-with-ant-1-8-2-tp3385716p3385931.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: project.createTask() not working with ant-1.8.2

Posted by Mohan <mo...@gmail.com>.
>> One thing to look out for apart from the obvious CLASSPATH environment
variable, ${ANT_HOME}/lib and ~/.ant/lib is the shell script you use to
launch Ant (I assume a Unix like system from ant.jar's path in your
error message). 

* I do not have the CLASSPATH variable set.  I also do not have the .ant
directory in my home directory.  But ANT_HOME is set to Ant 1.8.2.

* I'm not using any wrapper script for ant invocation. I'm invoking the ant
script directly from Ant-1.8.2/bin/ant as shown in the second update.

>> The most likely reason you see this error is that your Java VM has
loaded a different version of ant.jar

How can I check which version of ant.jar is getting loaded with the JVM?

I tried printing the command that is being executed in the Ant wrapper
script and it is:

exec "/usr/local/java/jdk/jre/bin/java" -classpath
"/prod/tools/infra/apache/ant-1.8.2/lib/ant-launcher.jar"
-Dant.home="/prod/tools/infra/apache/ant-1.8.2"
-Dant.library.dir="/prod/tools/infra/apache/ant-1.8.2/lib"
org.apache.tools.ant.launch.Launcher -cp ""

I do not see any other version of ant being loaded in this command.  Could
you let me know if I'm missing something?


Thanks,
Mohan.



-- 
View this message in context: http://ant.1045680.n5.nabble.com/project-createTask-not-working-with-ant-1-8-2-tp3385716p3385921.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: project.createTask() not working with ant-1.8.2

Posted by Mohan <mo...@gmail.com>.
>> If your really really really want to use "new Project()" you should make
sure it gets initialized properly by invoking the init() method on your new
instance before you call createTask.

This suggestion worked for us.  Thanks Stefan for the quick response!!
-- 
View this message in context: http://ant.1045680.n5.nabble.com/project-createTask-not-working-with-ant-1-8-2-tp3385716p3390678.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: project.createTask() not working with ant-1.8.2

Posted by Stefan Bodewig <bo...@apache.org>.
[Pulling together a few responses]

On 2011-02-15, Mohan wrote:

> I'm not using any wrapper script for ant invocation. I'm invoking the
> ant script directly from Ant-1.8.2/bin/ant as shown in the second
> update.

"the ant script directly from Ant-1.8.2/bin/ant" is the wrapper script I
was talking about ;-)

This is not the problem as we've seen by now.  Your stripped-down
example really helped, thanks a lot.

> Are you able to reproduce the issue using the code snippet provided?

Yes, and it led to
<https://issues.apache.org/bugzilla/show_bug.cgi?id=50788>.

I'll investigate this further (but it will take a day or two until I get
there).

> Just to clarify, if I use getProject(), I'm not getting an error.  But
> I would like to create a new Project in the Obfuscate's execute method
> where I want to run my tasks.

I won't pretend I understand why you'd want to do that.

The project instance is your tasks liaison to all things Ant.  Your new
project instance will use default values for several things (like the
logger) and not know anything about the customizations your "real"
project instance has received.

Anyway, there are ways to use separate instances.

If your task wants to run in a subcontext where it can set properties
that are not visible to other tasks (like <ant> does for the child
project) then the static Project.createSubProject method is the one you
want to use.

If your really really really want to use "new Project()" you should make
sure it gets initialized properly by invoking the init() method on your
new instance before you call createTask.  This should load the default
task definitions and make your problem go away (I just checked and it
works).

Stefan

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


Re: project.createTask() not working with ant-1.8.2

Posted by Vimil Saju <vi...@yahoo.com>.
 
> Just to clarify, if I use getProject(), I'm not getting an
> error.  But I
> would like to create a new Project in the Obfuscate's
> execute method where I
> want to run my tasks.
> 
> Is there no way to create a new Project and run the tasks
> that I want?

It s not advisable to create a new project unless there is a specific reason. If a new project is created, the task cannot access any of the properties or references defined in the project under which task is defined. 

If you want to execute your task under a new project all you need is to put the task under a separate target and the invoke the target using the antcall task.

If you really need to create a new Project object, i think it is not sufficient to just create an instance of the Project object. Look at the source code of antcall task to see how a new project is created.



 
____________________________________________________________________________________
It's here! Your new message!  
Get new email alerts with the free Yahoo! Toolbar.
http://tools.search.yahoo.com/toolbar/features/mail/

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


Re: project.createTask() not working with ant-1.8.2

Posted by Mohan <mo...@gmail.com>.
Just to clarify, if I use getProject(), I'm not getting an error.  But I
would like to create a new Project in the Obfuscate's execute method where I
want to run my tasks.

Is there no way to create a new Project and run the tasks that I want?

Thanks,
Mohan.
-- 
View this message in context: http://ant.1045680.n5.nabble.com/project-createTask-not-working-with-ant-1-8-2-tp3385716p3386140.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: project.createTask() not working with ant-1.8.2

Posted by Mohan <mo...@gmail.com>.
Stefan,

Are you able to reproduce the issue using the code snippet provided?

Thanks,
Mohan.

-- 
View this message in context: http://ant.1045680.n5.nabble.com/project-createTask-not-working-with-ant-1-8-2-tp3385716p3386125.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: project.createTask() not working with ant-1.8.2

Posted by Stefan Bodewig <bo...@apache.org>.
On 2011-02-15, bool wrote:

> createTask() method is throwing the following error with ant-1.8.2 while it
> works perfectly with Ant 1.7.1.

> import org.apache.tools.ant.taskdefs.Delete;
> Delete delete = (Delete) myProject.createTask("Delete");

> jar:file:/myant/ant-1.8.2/lib/ant.jar!/org/apache/tools/ant/antlib.xml:37:
> Problem: failed to create task or type componentdef

The task is defined in defaults.properties which is inside your ant.jar
in org/apache/tools/ant/taskdefs.

The most likely reason you see this error is that your Java VM has
loaded a different version of ant.jar - one before componentdef was
added as a task - before the one of Ant 1.8.2.  Ant would then load the
properties file from this jar and fail to recognize the task.

> I tried to remove all componentdef stuff from
> org/apache/tools/ant/antlib.xml and then it started working again.

But will cause other problems downstream.  You should rather try to
locate the "other" ant.jar and fix your situation.

One thing to look out for apart from the obvious CLASSPATH environment
variable, ${ANT_HOME}/lib and ~/.ant/lib is the shell script you use to
launch Ant (I assume a Unix like system from ant.jar's path in your
error message).

Ant's own wrapper script contains some modifications for RPM
installations that might pull in other jars depending your local setup
(it might get triggered inside /etc/ant.conf).  What is more likely is
that there is some system installed version of Ant that comes with yet
another wrapper script.

Stefan

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