You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Michael Molloy <mm...@RESORTQUEST.com> on 2001/08/02 16:41:10 UTC

Compile question--Class not found

Just started using Ant, and I can already appreciate all the work that has
been put into it. Great tool.

However, I'm having a bit of a problem. I've got packageA and packageB.
packageA uses some classes in packageB. I tried the following using ant.

1. Compile packageB
2. Put the jar in ant/lib.
3. Compile packageA.
4. Move both jar files to my Windows 2000 development box.
5. Issued the java command: java -cp packageB.jar;packageA.jar MainClass

This worked some of the time, but most of the time I got a
ClassNotFoundException: packageB/SomeClass. The class is there, though.

The only way I could get this to work was to move the packageB source files
into the packageA directory and then call ant on packageA. The resulting
single jar file packageA.jar works fine everytime. The problem is that I use
packageB classes in other applications, so this is not an optimal solution. 

Anyone have any suggestions? If it makes a difference, I'm compiling
everything on SuSE 7.1 with Sun JDK build 1.3.1-b24.

Thanks for any help.

--Michael

Re: Compile question--Class not found

Posted by Don Taylor <do...@yahoo.com>.
I don't understand what you're trying to accomplish with step 2.
ant/lib is where you put your own ant tasks or the optional ant tasks.
In any case, it's all ant-related. 

To solve your problem try compiling package B first and produce the jar
file ("b-jar"). Then when compiling package A make sure b-jar is in the
classpath. Then everything should be fine.

-- Don

--- Michael Molloy <mm...@RESORTQUEST.com> wrote:
> Just started using Ant, and I can already appreciate all the work
> that has
> been put into it. Great tool.
> 
> However, I'm having a bit of a problem. I've got packageA and
> packageB.
> packageA uses some classes in packageB. I tried the following using
> ant.
> 
> 1. Compile packageB
> 2. Put the jar in ant/lib.
> 3. Compile packageA.
> 4. Move both jar files to my Windows 2000 development box.
> 5. Issued the java command: java -cp packageB.jar;packageA.jar
> MainClass
> 
> This worked some of the time, but most of the time I got a
> ClassNotFoundException: packageB/SomeClass. The class is there,
> though.
> 
> The only way I could get this to work was to move the packageB source
> files
> into the packageA directory and then call ant on packageA. The
> resulting
> single jar file packageA.jar works fine everytime. The problem is
> that I use
> packageB classes in other applications, so this is not an optimal
> solution. 
> 
> Anyone have any suggestions? If it makes a difference, I'm compiling
> everything on SuSE 7.1 with Sun JDK build 1.3.1-b24.
> 
> Thanks for any help.
> 
> --Michael


__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

RE: Compile question--Class not found

Posted by Matt Lyon <ma...@stargus.com>.
Diane,

Thanks for the tip, that allows me to remove some serious redundancies from
my buildfiles.

Cheers,

Matt

-----Original Message-----
From: Diane Holt [mailto:holtdl@yahoo.com]
Sent: Friday, August 03, 2001 12:29 PM
To: ant-user@jakarta.apache.org
Subject: RE: Compile question--Class not found


--- Matt Lyon <ma...@stargus.com> wrote:
>                 <javac srcdir="${src}"
>                        destdir="${build.classes.dir}"
>                        includes="com\biz\packageb\**"
>                        classpath="${build.classes.dir}"
>                        optimize="on"/>

Just a note: The "destdir" directory is added to the classpath by the
<javac> task, so there's no need to include it again in "classpath".

Diane

=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/


RE: Compile question--Class not found

Posted by Diane Holt <ho...@yahoo.com>.
--- Matt Lyon <ma...@stargus.com> wrote:
>                 <javac srcdir="${src}"
>                        destdir="${build.classes.dir}"
>                        includes="com\biz\packageb\**"
>                        classpath="${build.classes.dir}"
>                        optimize="on"/>

Just a note: The "destdir" directory is added to the classpath by the
<javac> task, so there's no need to include it again in "classpath".

Diane

=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

RE: Compile question--Class not found

Posted by Matt Lyon <ma...@stargus.com>.
Michael,

I'm not sure if I'm understanding your question correctly, but couldn't you
<javac/> Package B to a common directory, say "../Build/classes", <javac/>
Package A passing in a classpath pointer to "../Build/classes", then <jar/>
up the classes you need using the includes parameter? Something like:

<target name="init">
<property name="build.dir" value="..\..\Build"/>
<property name="build.classes.dir" value="${build.dir}\classes"/>
<property name="src" value="..\..\src"/>
</target>

<target name="compile"
           depends="init:>
          <!-- Establish \Build directory structure. -->
          <mkdir dir="${build.classes.dir}"/>

          <!-- Compile Package A classes. -->
          <javac srcdir="${src}"
                    destdir="${build.classes.dir}"
                    includes="com\biz\packagea\**"
                    optimize="on"/>

                <!-- Compile Package B classes. -->
                <javac srcdir="${src}"
                       destdir="${build.classes.dir}"
                       includes="com\biz\packageb\**"
                       classpath="${build.classes.dir}"
                       optimize="on"/>
</target>

<target name="assemble"
           depends="compile"
           <!-- Assemble the jar module. -->
	<jar jarfile="${build.dir}\my.jar"
		     basedir="${build.classes.dir}"

includes="com\biz\packagea\somefilename,com\biz\packageb\somefilename"/>
</target>

I'm not sure if that was what you were asking though...

Cheers,

Matt


-----Original Message-----
From: Michael Molloy [mailto:mmolloy@RESORTQUEST.com]
Sent: Thursday, August 02, 2001 10:41 AM
To: 'ant-user@jakarta.apache.org'
Subject: Compile question--Class not found


Just started using Ant, and I can already appreciate all the work that has
been put into it. Great tool.

However, I'm having a bit of a problem. I've got packageA and packageB.
packageA uses some classes in packageB. I tried the following using ant.

1. Compile packageB
2. Put the jar in ant/lib.
3. Compile packageA.
4. Move both jar files to my Windows 2000 development box.
5. Issued the java command: java -cp packageB.jar;packageA.jar MainClass

This worked some of the time, but most of the time I got a
ClassNotFoundException: packageB/SomeClass. The class is there, though.

The only way I could get this to work was to move the packageB source files
into the packageA directory and then call ant on packageA. The resulting
single jar file packageA.jar works fine everytime. The problem is that I use
packageB classes in other applications, so this is not an optimal solution.

Anyone have any suggestions? If it makes a difference, I'm compiling
everything on SuSE 7.1 with Sun JDK build 1.3.1-b24.

Thanks for any help.

--Michael