Bug 37070 - [README] XDoclet support from within Eclipse
Summary: [README] XDoclet support from within Eclipse
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Ant (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.0 RC4   Edit
Assignee: Darin Wright CLA Friend
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-04-29 16:12 EDT by Archimedes Trajano CLA Friend
Modified: 2004-09-02 21:31 EDT (History)
3 users (show)

See Also:


Attachments
Build.xml with the taskdefs (1.24 KB, text/xml)
2003-04-29 16:13 EDT, Archimedes Trajano CLA Friend
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Archimedes Trajano CLA Friend 2003-04-29 16:12:25 EDT
I can't seem to find examples of people using XDoclet using the built in 
facilities in eclipse.  Namely specifing the XDoclet tasks in the preferences 
dialog instead of writing task defs.

Whenever I do this I get the following error with XDoclet 1.2.  I have put in 
all the jars in the lib directory from XDoclet.

Buildfile: C:\Program Files\Eclipse\workspace\JBossProject\build.xml
BUILD FAILED: file:C:/Program 
Files/Eclipse/workspace/JBossProject/build.xml:23: Can't create a ejbdoclet 
element under {2}. Make sure the jar file containing the corresponding subtask 
class is on the classpath specified in the <taskdef> that defined {2}.

I am not using 1.1 because my project path has a space in it and I get.

   [ejbdoclet] Javadoc execution
   [ejbdoclet] javadoc: Illegal package name: "C:\Program"
   [ejbdoclet] 2 errors
   [ejbdoclet] javadoc: File not 
found: "Files\Eclipse\workspace\JBossProject\src\net\trajano\umi\beans\NamedElem
entBean.java"
   [ejbdoclet] BUILD FAILED: file:C:/Program 
Files/Eclipse/workspace/JBossProject/build.xml:21: Javadoc returned 1
Comment 1 Archimedes Trajano CLA Friend 2003-04-29 16:13:50 EDT
Created attachment 4757 [details]
Build.xml with the taskdefs
Comment 2 Darin Swanson CLA Friend 2003-08-20 19:16:54 EDT
The ejbdoclet task creates a whole bunch of subtasks. To correctly load these 
subtasks, the ejbdoclet task needs to have the correct classpath. 

I don't fully understand why the Ant runtime classpath does not allow the 
correct loading of the subtasks but this is pretty low priority.
Comment 3 Derek Chen-Becker CLA Friend 2003-10-08 15:57:35 EDT
I have a very similar issue that I have resolved, so I'm noting it in this bug.
I was trying to use XDoclet support and I had defined a path entry for the
XDoclet JARs in my build.xml <i>as well as</i> in my Ant runtime classpath via
the preferences dialog. On the suggestion of Darin I removed the JARs from my
Ant runtime classpath preferences and the build worked. I tried the converse,
commenting out the classpath in my build file and adding the JARs in my Ant
runtime prefs, but that did not work. 

To summarize: to get XDoclet working I have to use a classpath element in my
build file to include the XDoclet JARs, not the Ant runtime classpath preferences.
Comment 4 Derek Chen-Becker CLA Friend 2003-10-09 15:40:05 EDT
Thanks. I have some very preliminary results here, but I see two major
differences in behavior:

1. With the XDoclet JARs in the Ant runtime classpath the class loader for
xdoclet.modules.hibernate.HibernateDocletTask is 

org.eclipse.ant.internal.core.AntClassLoader

The classpath then gets set to the return value of
System.getProperty("java.class.path") (xdoclet.loader.ModuleFinder, line  98).
This classpath (in my case) is simply 

"C:\\Program Files\\eclipse\startup.jar"

Which does not hold the xml module documents that XDoclet needs to define the
hibernate subtask, which is what the build error says in not so much detail.

2. Without the XDoclet JARs in the Ant runtime classpath the class loader for
xdoclet.modules.hibernate.HibernateDocletTask is 

org.apache.tools.ant.AntClassLoader

The classpath then gets set to the classpath for that loader (which is correct,
and contains the xml mapping docs).

The immediate problem is that the eclipse AntClassLoader is not actually a
subclass of the real Ant ClassLoader, so the xdoclet code throws a
ClassCastException. As far as I can tell, they both extend java.lang.ClassLoader
somewhere down the line, but I'm not sure what the specific requirements are for
XDoclet specifically asking for an org.apache.tools.AntClassLoader.
Comment 5 Darin Swanson CLA Friend 2003-10-09 16:11:51 EDT
Thanks for the info Derek. 
The XDoclet code does a hard cast to org.apache.tools.AntClassLoader?
Or is it that the ClassCastException is not from the classloaders but from some 
xdoc classes being cast to each other that are loaded by the different 
classloaders? Just guessing...
Comment 6 Derek Chen-Becker CLA Friend 2003-10-09 16:37:59 EDT
Definitely doing a hard cast. Here is the offending code from
xdoclet.loader.ModuleFinder, lines 93-100:

        if (System.getProperty("xdoclet.class.path") == null) {
            try {
                classpath = ((AntClassLoader)
clazz.getClassLoader()).getClasspath();
            }
            catch (ClassCastException e) {
                classpath = System.getProperty("java.class.path");
            }
        }

I think the reason they do it is that the base java.lang.ClassLoader doesn't
have an accessor for the classpath.
Comment 7 Darin Swanson CLA Friend 2003-10-09 16:44:27 EDT
So it looks to me like the good path for the Eclipse integration is to 
recommend that the user set the magic "xdoclet.class.path" property and not 
rely on using AntClassloader. The java.class.path for the Eclipse Ant 
classloader when in the same VM as Eclipse will always be the root directory of 
the Eclipse install. 
Ant in a separate VM which is support in 3.0 M3 and on, you can set the working 
directory to be whatever you desire and defaults to the parent folder of the 
Ant build file.

I am going to reopen so that we can address this in readme / known issues.
Comment 8 Derek Chen-Becker CLA Friend 2003-10-09 16:55:34 EDT
Either that, or just use the classpath attributes inside your buildfile.
Originally I tried using the Ant runtime classpath as a way to avoid writing the
<path> elements in my build file, but on second thought I think it makes more
sense from the Ant perspective to require explicit classpaths inside the build.
Comment 9 Darin Swanson CLA Friend 2003-10-09 18:59:38 EDT
I agree...you should not have to guess what is occurring while you are reading 
the buildfile. And it is much less error prone :-)
Comment 10 Darin Swanson CLA Friend 2004-06-22 14:12:16 EDT
Added to the Ant readme.
Comment 11 Darin Swanson CLA Friend 2004-06-22 14:12:34 EDT
Please verify DarinW.
Comment 12 Darin Wright CLA Friend 2004-08-05 11:17:09 EDT
Verified
Comment 13 Daniel Koller CLA Friend 2004-09-02 21:31:00 EDT
Hi,

I have this problem also. Could you please provide a sample build.xml entry to
fix this?

Kind regards,

Daniel