ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Reilly <peter.rei...@corvil.com>
Subject Re: BeanShellDef - java.lang.LinkageError: duplicate class definition: AList
Date Fri, 23 Jan 2004 09:07:46 GMT
Thanks,
  Yes I find it very usefull to write small tasks using beanshelldef.

  There is a  problem with antcall and beanshelldef.
The easiest work-around would be to place the definition in an init
target that gets called only if a property is not defined:

<target name="init-beanshell-tasks" unless="beanshell-tests-defined">
   <beanshelldef .../>
   <property name="beanshell-tasks-defined" value="yes"/>
</target>

About the beanshelldef, I have found that I can use BSF to do this and not
call beanshell directly. This will mean that the define will support any
BSF language that can export proper java classes and also make the
ant code independant of linking to beanshell.

The working title is reflectdef:

    <reflectdef name="hello" language="beanshell">
      import org.apache.tools.ant.Task;
      public class hello extends Task {
          public void execute() {
             log("Hello world");
          }
      }
      hello.class;
    </reflectdef>

    <hello/>


Currently the only language (I know) that can export a java class that 
can be
reflected is beanshell 2.0b1.  It looks like grovvy and pnuts may have this
ability. jython and rhino (As far as I can see) do not.

Peter

Michael Sunde wrote:

>Hi,
> 
>I have been playing with the beanshelldef class defined by Peter in thread:
>http://marc.theaimsgroup.com/?l=ant-dev <http://marc.theaimsgroup.com/?l=ant-dev&m=106577547220771&w=2>
&m=106577547220771&w=2
> 
>Occasionally, I get a duplicate class definition error when using a task defined by beanshelldef.
I can reproduce the problem by using antcall. The attached build file works fine if I call
the 'test' target but fails when the 'call' target is invoked. Is there a new version of BeanShellDef
with this problem fixed? It seems like beanshelldef is executed twice.
> 
>Since we know the name of the task that is being created, is it possible to delay the
compilation of the beanshelldef code until it is used, to improve startup performance?
> 
>Ant version: 1.6
>BeanShell: 2.0beta1
> 
>This task has turned out to be extremely useful. I hope it makes it into the next version
of ant. 
> 
>Thanks,
>Michael
> 
>build.xml
>=============================
><project name="echo" basedir=".">
>    <typedef name="beanshelldef" classname="BeanShellDef"/>
>    <beanshelldef name="test1" classname="AList">
>      import org.apache.tools.ant.Task;
>      public class AList extends Task {
>         String message = null;
>         public void setMessage(String message) {
>             this.message = message;
>         }
>         public void execute() {
>            System.out.println("message is " + message);
>         }
>     }
>    </beanshelldef>
>    <test1 message="hello world"/>
> 
>    <macrodef name="testMacro">
>        <attribute name="message"/>
>        <sequential>
>            <test1 message="@{message}"/>
>        </sequential>
>    </macrodef>
>    <testMacro message="Hello from Macro"/>
>    
>    <target name="test">
>        <test1 message="hello from target test"/>
>        <testMacro message="hello from target test in macro"/>
>    </target>
>    
>    <target name="call">
>        <antcall target="test"/>
>    </target>
></project>
>
> 
>Error
>=============================
>E:\builds\sst2>ant  call
>Buildfile: build.xml
>    [test1] message is hello world
>    [test1] message is Hello from Macro
> 
>call:
>[beanshelldef] java.lang.reflect.InvocationTargetException
>[beanshelldef]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>[beanshelldef]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>[beanshelldef]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>[beanshelldef]  at java.lang.reflect.Method.invoke(Method.java:324)
>[beanshelldef]  at bsh.Reflect.invokeOnMethod(Unknown Source)
>[beanshelldef]  at bsh.Reflect.invokeObjectMethod(Unknown Source)
>[beanshelldef]  at bsh.BshClassManager.defineClass(Unknown Source)
>[beanshelldef]  at bsh.ClassGeneratorImpl.generateClassImpl(Unknown Source)
>[beanshelldef]  at bsh.ClassGeneratorImpl.generateClass(Unknown Source)
>[beanshelldef]  at bsh.BSHClassDeclaration.eval(Unknown Source)
>[beanshelldef]  at bsh.Interpreter.eval(Unknown Source)
>[beanshelldef]  at bsh.Interpreter.eval(Unknown Source)
>[beanshelldef]  at bsh.Interpreter.eval(Unknown Source)
>[beanshelldef]  at BeanShellDef.execute(BeanShellDef.java:95)
>[beanshelldef]  at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:306)
>[beanshelldef]  at org.apache.tools.ant.Task.perform(Task.java:401)
>[beanshelldef]  at org.apache.tools.ant.Target.execute(Target.java:338)
>[beanshelldef]  at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:172)
>[beanshelldef]  at org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java:126)
>[beanshelldef]  at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:382)
>[beanshelldef]  at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:144)
>[beanshelldef]  at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:306)
>[beanshelldef]  at org.apache.tools.ant.Task.perform(Task.java:401)
>[beanshelldef]  at org.apache.tools.ant.Target.execute(Target.java:338)
>[beanshelldef]  at org.apache.tools.ant.Target.performTasks(Target.java:365)
>[beanshelldef]  at org.apache.tools.ant.Project.executeTarget(Project.java:1237)
>[beanshelldef]  at org.apache.tools.ant.Project.executeTargets(Project.java:1094)
>[beanshelldef]  at org.apache.tools.ant.Main.runBuild(Main.java:669)
>[beanshelldef]  at org.apache.tools.ant.Main.startAnt(Main.java:220)
>[beanshelldef]  at org.apache.tools.ant.launch.Launcher.run(Launcher.java:215)
>[beanshelldef]  at org.apache.tools.ant.launch.Launcher.main(Launcher.java:90)
>[beanshelldef] Caused by: java.lang.LinkageError: duplicate class definition: AList
>[beanshelldef]  at java.lang.ClassLoader.defineClass0(Native Method)
>[beanshelldef]  at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
>[beanshelldef]  at java.lang.ClassLoader.defineClass(ClassLoader.java:431)
>[beanshelldef]  ... 31 more
>[beanshelldef] bsh.InterpreterError: Unable to define class: java.lang.reflect.InvocationTargetException
>[beanshelldef]  at bsh.BshClassManager.defineClass(Unknown Source)
>[beanshelldef]  at bsh.ClassGeneratorImpl.generateClassImpl(Unknown Source)
>[beanshelldef]  at bsh.ClassGeneratorImpl.generateClass(Unknown Source)
>[beanshelldef]  at bsh.BSHClassDeclaration.eval(Unknown Source)
>[beanshelldef]  at bsh.Interpreter.eval(Unknown Source)
>[beanshelldef]  at bsh.Interpreter.eval(Unknown Source)
>[beanshelldef]  at bsh.Interpreter.eval(Unknown Source)
>[beanshelldef]  at BeanShellDef.execute(BeanShellDef.java:95)
>[beanshelldef]  at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:306)
>[beanshelldef]  at org.apache.tools.ant.Task.perform(Task.java:401)
>[beanshelldef]  at org.apache.tools.ant.Target.execute(Target.java:338)
>[beanshelldef]  at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:172)
>[beanshelldef]  at org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java:126)
>[beanshelldef]  at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:382)
>[beanshelldef]  at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:144)
>[beanshelldef]  at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:306)
>[beanshelldef]  at org.apache.tools.ant.Task.perform(Task.java:401)
>[beanshelldef]  at org.apache.tools.ant.Target.execute(Target.java:338)
>[beanshelldef]  at org.apache.tools.ant.Target.performTasks(Target.java:365)
>[beanshelldef]  at org.apache.tools.ant.Project.executeTarget(Project.java:1237)
>[beanshelldef]  at org.apache.tools.ant.Project.executeTargets(Project.java:1094)
>[beanshelldef]  at org.apache.tools.ant.Main.runBuild(Main.java:669)
>[beanshelldef]  at org.apache.tools.ant.Main.startAnt(Main.java:220)
>[beanshelldef]  at org.apache.tools.ant.launch.Launcher.run(Launcher.java:215)
>[beanshelldef]  at org.apache.tools.ant.launch.Launcher.main(Launcher.java:90)
> 
>BUILD FAILED
>E:\builds\sst2\build.xml:33: Following error occured while executing this line
>E:\builds\sst2\build.xml:5: Sourced file: inline evaluation of: ``       import org.apache.tools.ant.Task;
      public class AList extends Task { . . . '' internal Error: Unable to define class: java.
>lang.reflect.InvocationTargetException : at Line: 3 : in file: inline evaluation of: ``
      import org.apache.tools.ant.Task;       public class AList extends Task { . . . '' :
public class AList ex
>tends Task {
> 
>
>Total time: 6 seconds
>
> 
> 
> 
> 
>
>  
>


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


Mime
View raw message