The Artima Developer Community
Sponsored Link

Java Answers Forum
problems at compilation when I try to use packages

2 replies on 1 page. Most recent reply: Aug 13, 2002 4:21 PM by Julio C. Fonseca C.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Julio C. Fonseca C.

Posts: 18
Nickname: jfonseca
Registered: Mar, 2002

problems at compilation when I try to use packages Posted: Aug 12, 2002 7:23 PM
Reply to this message Reply
Advertisement
Hi,

This is my problem, maybe it's a common question but I find quite important to solve it as soon as possible, so I post it on the forum.

I want to compile recurrent object files, that is, I use objects from one class in another file and viceversa through packages and import directives.

There are my classes,
//A.java

package Dir1;

import Dir2.*;

public class A
{
int a;
B b;
}

//B.java
package Dir2;

import Dir1.*;

public class B
{
int b;
A a;
}

The directory hierarchy for file A.java is Dir1\A.java, and for B.java it is Dir2\B.java

But I'm really confused when I try to do JAR archieves to use'em in the classpath compiler option, what files do I have to compile first?

I would like to maintain the same clean structure of the packages ('cause I working in a very major project.)

Thanks in advance,
Julio


Kishori Sharan

Posts: 211
Nickname: kishori
Registered: Feb, 2002

Re: problems at compilation when I try to use packages Posted: Aug 12, 2002 9:07 PM
Reply to this message Reply
This kind of circular dependency is automaticaaly handled by Java compiler. It doesn't matter which file you compile first A.java or B.java. If you compile A.java using javac then B.java will be compiled as well and vice-versa. So, just try to compile A.java and you will have both A.class and B.class .

Thanks
Kishori

Julio C. Fonseca C.

Posts: 18
Nickname: jfonseca
Registered: Mar, 2002

Re: problems at compilation when I try to use packages Posted: Aug 13, 2002 4:21 PM
Reply to this message Reply
Hi Kishori,

Maybe I didn't explain ok,

I already know what you said, but I was gotting the following errors,

C:\Documents and Settings\computo\My Documents\Julio\Pruebas\Dir1>javac A.java
A.java:3: package Dir2 does not exist
import Dir2.*;
^
A.java:8: cannot resolve symbol
symbol : class B
location: class Dir1.A
B b;
^
2 errors


But AT THIS TIME I solved the problem compiling in the parent directory, and using the option
-classpath .
, that is, with the following command line.

C:\Documents and Settings\computo\My Documents\Julio\Pruebas>javac -classpath .
Dir1\A.java

and it works very fine!,

anyway, thanks.

Flat View: This topic has 2 replies on 1 page
Topic: Java FTP composant on web browser Previous Topic   Next Topic Topic: ORA-1461

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use