ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Ludwig <mil...@gmx.de>
Subject Re: Mail task with mail.jar & activation.jar out of lib folder
Date Thu, 20 Jan 2011 02:46:05 GMT
Michael Ludwig schrieb am 19.01.2011 um 13:51 (+0100):
> Patrick Martin schrieb am 19.01.2011 um 10:31 (+0100):

> > D:\tmp\build.xml:7: taskdef A class needed by class
> > org.apache.tools.ant.taskdefs.email.MimeMailer cannot be found:
> > javax/mail/MessagingException
> >  using the classloader AntClassLoader[D:\tmp\a\activation.jar]
> 
> Only activation.jar in this classloader. But even when I put all
> required JARs into that custom classloader, it fails:
> 
>     <path id="mail.path">
>         <pathelement location="${ant.home}/lib/ant-javamail.jar" />
>         <pathelement location="${javamail.dir}/mail.jar" />
>         <fileset dir="${javamail.dir}/lib">
>             <include name="**/*.jar"/>
>         </fileset>
>         <pathelement location="${jlb.dir}/activation.jar" />
>     </path>
> 
>     <taskdef name="mymail"
>         classpathref="mail.path"
>         classname="org.apache.tools.ant.taskdefs.email.EmailTask" />
> 
> T:\MiLu\mail-jar.xml:25: java.lang.ClassNotFoundException: javax.mail.internet.MimeMessage
>         at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
>         at java.lang.Class.forName0(Native Method)
>         at java.lang.Class.forName(Class.java:169)
>         at org.apache.tools.ant.taskdefs.email.EmailTask.execute(EmailTask.java:452)
>         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.helper.ProjectHelper2.parse(ProjectHelper2.java:179)
>         at org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java:82)
>         at org.apache.tools.ant.Main.runBuild(Main.java:786)
>         at org.apache.tools.ant.Main.startAnt(Main.java:218)
>         at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
>         at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
> 
> It seems you have to use the main classloader, not a self-defined one.
> But I might be wrong. And even if not, I don't know why. For the
> experts to clarify.

Okay, thanks to the <ClassloaderTask>, it now works. (See script.)

But I still haven't understood the underlying issue. What's so special about
mail.jar that it needs special treatment?

I noticed its MANIFEST.MF contains lots of checksums. Do they cause problems
for additional classloaders defined in Ant?

  Name: javax/mail/search/SearchTerm.class
  SHA1-Digest: JveDH0FF1JcVa7wJL7mLJ48Vwd4=

Here's the working script:

<!-- vim: set filetype=ant: -->
<project>
	<property name="jlb.dir" location="G:\JLib"/>
	<property name="javamail.dir" location="${jlb.dir}/javamail-1.4.1"/>

	<path id="mail.path">
		<pathelement location="${javamail.dir}/mail.jar" />
		<!-- not needed:
		<fileset dir="${javamail.dir}/lib"><include name="**/*.jar"/></fileset>
		<pathelement location="${jlb.dir}/activation.jar" />
		-->
	</path>

	<!-- http://enitsys.sourceforge.net/ant-classloadertask/ -->
	<!-- JAR liegt in ~/.ant/lib -->
	<taskdef name="classloadertask"
		classname="org.apache.tools.ant.taskdefs.ClassloaderTask"/>
	<!-- nachrüsten -->
	<classloadertask classpathRef="mail.path" loader="thread"/>

	<property name="address" value="test@gmx.de"/>
	<property name="password" value="secret"/>

	<mail from="${address}"
		mailhost="mail.gmx.de" ssl="yes" mailport="465"
		user="${address}" password="${password}"
		subject="Ant Mail Test">
		<to address="test@yahoo.de"/>
	</mail>
</project>

-- 
Michael Ludwig

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


Mime
View raw message