wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes how to compile file which include Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to compile file which include "package" using javac" Watch "how to compile file which include "package" using javac" New topic
Author

how to compile file which include "package" using javac

snow snow
Greenhorn

Joined: Feb 21, 2003
Posts: 1
just help me ,here is the example :
package a.b;
public class Test1{
public void test(){
System.out.println("hello");
}
}
package a.c;
import a.b.Test1;
public class Test2{
public static void main(String args[]){
Test1 t1= new Test1();
T1.test()
}
}
i have compile Test1.java ---javac -d c:\jdk14\Test Test1.java
how can i complie Test2.java using javac ???
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
snow snow,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Change to
t1.test();

It then should compile in the same way as your first file.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
kobe bryan
Greenhorn

Joined: Feb 21, 2003
Posts: 2
to Barry Gaunt :
it doesn't work.
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

well T1.test(); will absolutely never work. The test method is not static, and therefore you need an instance to access it.

I think the problem is related to classpath and using the -d switch with javac. But The original poster doesn't give us any error output, so I'm only speculating.

Scenario:

You compile the first file. Fine. Where does the generated class file go? If you're leaving it in the same directory as your source files for both classes, then this is a problem.

There are two posts that talk about compiling trouble that might be relevant here. One is from the Java In General forum some time ago, and another is about servlets, but they both refer to using the -d switch.

Problem with Packages / Utility Classes in Servlets
(this one links to another thread.. it's worth a read as well).

ARGH! Package problem while using *
(the key to this one is in my second to last post, the 3rd last post in the thread. The paragraph that starts "In my case...". But don't just read from here; if you're still unsure after reading the whole thing, then focus on that paragraph.)
kobe bryan
Greenhorn

Joined: Feb 21, 2003
Posts: 2
Perfectly ,Mike Curwen .i think you have got snow's idea.
i have checked your list "url",and got the answer which were frustrating to me before,thanks .
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
to Barry Gaunt :
it doesn't work.

Actually it does work, and I know because I took your files, corrected them, compiled them, and run the program.

-Barry
[ February 21, 2003: Message edited by: Barry Gaunt ]
 
Consider Paul's rocket mass heater.
 
subject: how to compile file which include "package" using javac
 
Similar Threads
Regarding Package
How to get the handle of focused window
doubt ->Accessing from default package
cloning
Public Class in a source file