Hello. Here's a total newbie question. Suppose I have a packages (Linux):
/com.mine1
/com.mine2
Well, com.mine1 and com.mine2 both have classes in them that refer to one
another via import statement. Well, when trying to compile stuff in
com.mine1, I of course get the error of class not found, since com.mine2
classes haven't been compiled, but I can't do that because trying to compile
com.mine2 can't find com.mine1 classes yet. How do I compile these? I know
that if I create a .java file and import com.mine1 and com.mine2 and do a
javac on this file that everything will get compiled, but if I use a tool
like ant without doing that, how the heck do I resolve this? Thanks in
advance.
Anders - 24 Feb 2004 16:28 GMT
> Hello. Here's a total newbie question. Suppose I have a packages (Linux):
>
[quoted text clipped - 10 lines]
> like ant without doing that, how the heck do I resolve this? Thanks in
> advance.
I guess you can compile one of them if there is a class file of the
other but if both have no class file your in trouble.
Create class1 - compile
Create class2 with ref to class1 - compile
Add ref to class 2 in class 1 - compile
Maybe you can rethink your design and avoid circular reference by adding
an interface ?
Martin - 26 Feb 2004 10:17 GMT
> > Hello. Here's a total newbie question. Suppose I have a packages (Linux):
> >
[quoted text clipped - 20 lines]
> Maybe you can rethink your design and avoid circular reference by adding
> an interface ?
Hi John,
I'm curious about your "package situation", because I agree to Anders'
advice of rethinking your design.
Could you tell us (perhaps without giving away sensitive
project-information), in which way both packages refer to each other?
I'm not really experienced in big projects, but I'd like to know if
there is a good reason for this solution.
Martin
bangalore buddha - 24 Feb 2004 20:07 GMT
I created same type of pattern in NETBEANS ide and compiled. It did
compile with any problem.
I know Netbeans is available in LINUX env. Just try using
netbeans..ide..
John Ruiz - 25 Feb 2004 10:32 GMT
> I created same type of pattern in NETBEANS ide and compiled. It did
> compile with any problem.
>
> I know Netbeans is available in LINUX env. Just try using
> netbeans..ide..
Hiya guys. Thanks for the reply. Yeah, the code actually is for a
particular company I'm working for, so I'm not able to make changes.
Apparently, the developer uses an IDE, so everything compiles, but it makes
me wonder how the heck does the IDE do it then you know because obviously,
if an IDE can do it, it should be able to be done by hand I assume. I guess
I'll do a kludge and create like a dummy class that imports both and compile
that, which'll compile the classes in both packages. I wonder if this
problem is common seeing that if there's like many, many developers, I would
imagine that this situation could happen unsurprisingly.
Gregory A. Swarthout - 26 Feb 2004 18:41 GMT
> > I created same type of pattern in NETBEANS ide and compiled. It did
> > compile with any problem.
[quoted text clipped - 11 lines]
> problem is common seeing that if there's like many, many developers, I would
> imagine that this situation could happen unsurprisingly.
Compile them both with a single call to eliminate this problem.
John Ruiz - 29 Feb 2004 11:23 GMT
> > > I created same type of pattern in NETBEANS ide and compiled. It did
> > > compile with any problem.
[quoted text clipped - 13 lines]
>
> Compile them both with a single call to eliminate this problem.
Hiya. Yeah, I recall now being able to do that I think, but I just can't
get it to work using ant, since (I think) there's no way to do that?
Mykola Rabchevskiy - 26 Feb 2004 20:18 GMT
I made test:
[../a/A.java]-------
package a;
import b.*;
public class A {
B b = new B();
void f(){}
}
[../b/B.java]--------
package b;
import a.*;
public class B {
A a = new A();
void f(){}
}
When run javac for one (any) of these files both classes a.A and was
compiled without any problem (compiler 1.4.0 and 1.5.0).
Regards
M.Rabchevskiy
> Hello. Here's a total newbie question. Suppose I have a packages (Linux):
>
[quoted text clipped - 10 lines]
> like ant without doing that, how the heck do I resolve this? Thanks in
> advance.
Oskar Sigvardsson - 27 Feb 2004 01:34 GMT
> Hello. Here's a total newbie question. Suppose I have a packages (Linux):
>
[quoted text clipped - 10 lines]
> like ant without doing that, how the heck do I resolve this? Thanks in
> advance.
I'm pretty sure you just do like this. Say you have Class1 and Class2
(code in Class1.java and Class2.java) and they refer to eachother, you
compile it like this:
javac Class1.java Class2.java
or you could do it like this:
javac *.java
But that'd compile every java-file in the directory. Of course if
they're in different directories:
javac path1/Class1.java path2/Class2.java
Hope this helps...
Oskar Sigvardsson