Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 344518 - Ant 1.8.x reports build failed when optional jars are missing
Summary: Ant 1.8.x reports build failed when optional jars are missing
Status: RESOLVED WORKSFORME
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Ant (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-Ant-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: Documentation, readme
Depends on:
Blocks:
 
Reported: 2011-05-02 21:46 EDT by Martin Oberhuber CLA
Modified: 2011-05-16 16:37 EDT (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Oberhuber CLA 2011-05-02 21:46:39 EDT
With Eclipse 3.7m6 and later, the ant EmailTask fails with a J2SE-1.5 runtime:

Caused by: java.lang.ClassNotFoundException: javax.activation.DataHandler
        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 org.eclipse.ant.internal.core.AntClassLoader.findClass(AntClassLoader.java:54)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:164)
        at org.apache.tools.ant.taskdefs.email.EmailTask.execute(EmailTask.java:451)
        ... 104 more

This didn't happen in 3.7m5.
It looks like javax.activation.DataHandler has been a J2EE class since 1.4, and got into J2SE as per 1.6:
http://download.oracle.com/javase/6/docs/api/javax/activation/DataHandler.html
Comment 1 Remy Suen CLA 2011-05-02 22:18:05 EDT
Probably caused by bug 302296?
Comment 2 Martin Oberhuber CLA 2011-05-03 03:51:14 EDT
Most likely, yes. This change of behavior should probably be listed in the migration guide for 3.7.
Comment 3 Michael Rennie CLA 2011-05-03 10:20:45 EDT
Apparently you need additional jars now to make the mail tasks work.

Found on the Ant 1.8.2 user guide in the Library Dependencies section (http://ant.apache.org/manual/install.html#librarydependencies):

mail.jar is required for the Mail task with Mime encoding, and the MimeMail task - can be found at: http://www.oracle.com/technetwork/java/index-jsp-139225.html

activation.jar	is required for the Mail task with Mime encoding, and the MimeMail task - can be found at http://www.oracle.com/technetwork/java/javase/jaf-135115.html

The recommended course of action from Apache is to install all of the dependencies as described: http://ant.apache.org/manual/install.html#optionalTasks. I am not sure this is desired though as that will pull in all the dependencies for all of the optional tasks on that list - which looks like a lot of them.

I think the best solution would be to provide all of the optional jars in org.apache.ant (in orbit) so that all of the functionality is maintained from the pre-1.8.x version of Ant. Although this could be problematic due to the different licenses for the optional jars.

This definitely needs to be in the migration guide.
Comment 4 Michael Rennie CLA 2011-05-03 10:29:04 EDT
A quick sum-up of our possible solutions:

1. An entry in the migration guide (required)
2. provide any optional jars in org.apache.ant to maintain pre-1.8.x functionality
3. roll an additional version of org.apache.ant that contains all of the optional Ant jars - similar to the mutli-version of JUnit, for example.

Thoughts?
Comment 5 Dani Megert CLA 2011-05-03 10:32:06 EDT
> 1. An entry in the migration guide (required)
> 2. provide any optional jars in org.apache.ant to maintain pre-1.8.x
> functionality
> 3. roll an additional version of org.apache.ant that contains all of the
> optional Ant jars - similar to the mutli-version of JUnit, for example.
> 
> Thoughts?
My vote at this point would be 2. (assuming there are no legal restrictions that prohibit this).

I've added it as discussion topic for tomorrow's PMC call.
Comment 6 Martin Oberhuber CLA 2011-05-03 10:37:04 EDT
Well I can only talk about my own experience here, doing builds with PDE build
on build.eclipse.org.

For me personally, the ant mail task never worked - my build log always had
"failed to initialize MIME Mail", but apart from that message printed in the
log, I knew the build was OK.

With the new ant, I now get a backtrace which means I can no longer analyze my
build log properly. It's unclear whether the build itself failed or succeeded,
because the backtrace due to mail not available masks other errors.

I guess for me personally, catching the ClassNotLoadException from mail and
handling it in a nicer fashion would be an OK workaround that wouldn't require
me to download / install additional dependencies. 

Others, who do need mail to work (and had it working in previous releases) may
think differently. I'm adding Kim for comment.
Comment 7 Martin Oberhuber CLA 2011-05-03 10:43:04 EDT
On another note, shipping activation.jar with Eclipse may not be a great idea since "The JavaBeans Activation Framework 1.1.1 final release is included with the Java SE 6 release". 

I'm not sure about other depdencies, but personally I'd prefer instructions how to get PDE Build / ant to run with J2SE-1.6 which I'm using anyways. When we ship JAF-1.1.1 with Eclipse, then depending on classpath load order, the wrong copy might be loaded.
Comment 8 Dani Megert CLA 2011-05-03 10:43:39 EDT
If I understood correctly, then also other (newly optional) tasks are affected.
Comment 9 John Arthorne CLA 2011-05-03 10:58:50 EDT
Before figuring out solutions, I just want to make sure I understand the problem. Is this a correct assessment?

- The Ant Mail task is an optional task, meaning it may require additional libraries to function
- In Ant 1.7, the Mail task did not require additional libraries, but in Ant 1.8 it may require java mail if you use Mime encoding in your mail
- Java mail is available as a separate download for Java SE 5, and is included in Java SE 6.
- Java Mail is available in Orbit
Comment 10 Dani Megert CLA 2011-05-03 12:08:50 EDT
Mike, can you verify whether the set of available tasks changed (especially reduced) from 1.7 to 1.8? That's the first thing we need to know for sure.
Comment 11 Michael Rennie CLA 2011-05-03 12:43:18 EDT
(In reply to comment #9)
> Before figuring out solutions, I just want to make sure I understand the
> problem. Is this a correct assessment?
> 
> - The Ant Mail task is an optional task, meaning it may require additional
> libraries to function

Correct. I discovered the link I posted above to get mail.jar is a dead link, so I ran 

%> ant -f fetch.xml -Ddest=optional

to pull in all of the optional jars and discovered Apache is calling it mail-1.4.jar

> - In Ant 1.7, the Mail task did not require additional libraries, but in Ant
> 1.8 it may require java mail if you use Mime encoding in your mail

Checking the previous versions of Ant (1.6.x, 1.7.x and 1.8.x) the mail task still did require the additional jars to run properly. The confusion comes in for versions < 1.8.x because the message reported from the mail task looks like:

Buildfile: C:\Users\mrennie\workspaces\workspace3.4.x\AntTest\mail.xml
main:
     [mail] Failed to initialise MIME mail: javax/mail/MessagingException
BUILD SUCCESSFUL
Total time: 124 milliseconds

as opposed to the new message which is a stack trace and correctly reports the build has failed. Note this is the message from Apache, not an Eclipse message.

> - Java mail is available as a separate download for Java SE 5, and is included
> in Java SE 6.

My understanding is that it is, but from my testing - using 1.5 and 1.6 - the mail task in Ant will still not work properly unless you add the mail-1.4.jar file to the Ant classpath.

> - Java Mail is available in Orbit

I am not sure about this.

> Mike, can you verify whether the set of available tasks changed (especially
> reduced) from 1.7 to 1.8? That's the first thing we need to know for sure.

I scanned through the supplied jar files and the classes from ant 1.8.x and 1.7.1 and found:

1. 1.8.x added ant-apache-xalan2.jar which adds xalan to trace support
2. 1.8.x added ant-junit4.jar for JUnit 4 support
3. 1.8.x removed no-deps.jar - according to the release notes it has been merged into ant.jar (http://www.apache.org/dist/ant/RELEASE-NOTES-apache-ant-1.8.2.html)
4. 1.8.x removed ant-starteam.jar - removed because they did not work without additional deps (http://ant.1045680.n5.nabble.com/VOTE-Weblogic-and-Starteam-antlibs-for-ant-1-8-0-td1371107.html)
5. 1.8.x removed ant-stylebook.jar because it has been deprecated for a long time (http://ant.1045680.n5.nabble.com/removing-ant-stylebook-td1358185.html)
6. 1.8.x removed ant-trax.jar - merged it into ant.jar
7. 1.8.x removed ant-weblogic.jar - removed because they did not work without additional deps (http://ant.1045680.n5.nabble.com/VOTE-Weblogic-and-Starteam-antlibs-for-ant-1-8-0-td1371107.html)
8. 1.8.x added ant-testutil.jar which added test utilities.

To sum up: the starteam and weblogic tasks are no longer present, but they had a dependency on third party commercial jars so the likely-hood of them being used is very small. Ant stopped shipping them because of this and the fact the weblogic supply their own tasks now. See http://ant.1045680.n5.nabble.com/VOTE-Weblogic-and-Starteam-antlibs-for-ant-1-8-0-td1371107.html for the complete discussion about it.
Comment 12 John Arthorne CLA 2011-05-03 13:08:24 EDT
(In reply to comment #11)
> Checking the previous versions of Ant (1.6.x, 1.7.x and 1.8.x) the mail task
> still did require the additional jars to run properly. The confusion comes in
> for versions < 1.8.x because the message reported from the mail task looks
> like:

Thanks for digging up all these details Michael. If the only change from 1.7 to 1.8 is that the build failure is now reported correctly in this case (using Mail task without mail library), I think all we need to do is document it.
Comment 13 Dani Megert CLA 2011-05-04 10:28:23 EDT
> Thanks for digging up all these details Michael. If the only change from 1.7 to
> 1.8 is that the build failure is now reported correctly in this case (using
> Mail task without mail library), I think all we need to do is document it.

+1!
Comment 14 Michael Rennie CLA 2011-05-16 16:37:29 EDT
Marking as worksforme as the new 1.8.x behavior is working as intended. I have also updated the Eclipse readme file with migration information.