You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Leon Pu <le...@yahoo.com.cn> on 2005/11/29 16:18:54 UTC

Confusion of jar in Ant's classpath and system's CLASSPATH

Hi all,

I met a very strange problem that one jar doesn't become useful after I
put it to Ant classpath setting, ClassNotFoundException will be thrown
out. After I put the jar to system's CLASSPATH, Ant target runs without
problem.

The cannot be found java class in the special jar is not directly used
by my program, it is invoked by the java class which locate in other
jar.

Here is the sample classpath declaration in my build script. Class
com.foo.task.MyTask extends org.apache.tools.ant.Task, it is included
in 1-1.jar. The ClassNotFound class is located in 2-1.jar which will be
invoked by the class in 3-1.jar.

[build-script]
  <path id="run.class.path">
    <pathelement location="${basic.build.dir}" />
    <fileset dir="${internals.lib.dir}/component1">
      <include name="**/1-1.jar" />
    </fileset>
    <fileset dir="${internals.lib.dir}/component2">
      <include name="**/2-1.jar" />
    </fileset>
    <fileset dir="${internals.lib.dir}/component3">
      <include name="**/3-1.jar" />
    </fileset>
  </path>

  <property name="run.class.path" refid="run.class.path" />

  <target name="run.task">
    <taskdef name="mytask" classname="com.foo.task.MyTask"
classpath="${run.class.path}" />
    <mytask arg1="${arg1}" arg2="${arg2}" />
  </target>
[build-script]


Best regards,
Leon



	
		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com

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


Re: Confusion of jar in Ant's classpath and system's CLASSPATH

Posted by Dominique Devienne <dd...@gmail.com>.
> > How so invoked? Is that class that's not found used directory by the
> > code, or indirectly thru a Class.forName() call? If the later, you
> > may
> > need to use the Context ClassLoader to correctly locate the class
> > (see
> > overloaded form of forName()).
> >
> > Could be something else too, but it's not easy to diagnose with the
> > information you provided. Class loading issues are tricky. --DD
>
> the missed class is invoked by Class.forName().
> Could you give some detailed information about the Context ClassLoader?
> Thanks you for your hint.

You're welcome. I suggest you research it a bit yourself ;-) Ted
Neward has an excellent White Paper on class loaders in general. See
the javadocs for Thread.getContextClassLoader() and
Class.forName(String name, boolean initialize, ClassLoader loader).
--DD

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


Re: Confusion of jar in Ant's classpath and system's CLASSPATH

Posted by Leon Pu <le...@yahoo.com.cn>.
--- Dominique Devienne <dd...@gmail.com> wrote:

> > I met a very strange problem that one jar doesn't become useful
> after I
> > put it to Ant classpath setting, ClassNotFoundException will be
> thrown
> > out. After I put the jar to system's CLASSPATH, Ant target runs
> without
> > problem. [...]
> > Here is the sample classpath declaration in my build script. Class
> > com.foo.task.MyTask extends org.apache.tools.ant.Task, it is
> included
> > in 1-1.jar. The ClassNotFound class is located in 2-1.jar which
> will be
> > invoked by the class in 3-1.jar.
> 
> How so invoked? Is that class that's not found used directory by the
> code, or indirectly thru a Class.forName() call? If the later, you
> may
> need to use the Context ClassLoader to correctly locate the class
> (see
> overloaded form of forName()).
> 
> Could be something else too, but it's not easy to diagnose with the
> information you provided. Class loading issues are tricky. --DD

Hi Dominique,

the missed class is invoked by Class.forName().

Could you give some detailed information about the Context ClassLoader?

Thanks you for your hint.


Best regards,
Leon


		
__________________________________________
Yahoo! DSL – Something to write home about.
Just $16.99/mo. or less.
dsl.yahoo.com


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


Re: Confusion of jar in Ant's classpath and system's CLASSPATH

Posted by Dominique Devienne <dd...@gmail.com>.
> I met a very strange problem that one jar doesn't become useful after I
> put it to Ant classpath setting, ClassNotFoundException will be thrown
> out. After I put the jar to system's CLASSPATH, Ant target runs without
> problem. [...]
> Here is the sample classpath declaration in my build script. Class
> com.foo.task.MyTask extends org.apache.tools.ant.Task, it is included
> in 1-1.jar. The ClassNotFound class is located in 2-1.jar which will be
> invoked by the class in 3-1.jar.

How so invoked? Is that class that's not found used directory by the
code, or indirectly thru a Class.forName() call? If the later, you may
need to use the Context ClassLoader to correctly locate the class (see
overloaded form of forName()).

Could be something else too, but it's not easy to diagnose with the
information you provided. Class loading issues are tricky. --DD

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