| Author |
package problem -- ant ?
|
Edward Chen
Ranch Hand
Joined: Dec 23, 2003
Posts: 756
|
|
In the above project, Test.B.java use A.java object and Util.C.java object. How can I write build.xml file to compile / run Test.B.java ? Here, A.java is a plain file, not belong to any package. Test.B.java is packaged into Test. Util.C.java is packaged into Util which is located in src directry. Thanks
|
 |
Bear Bibeault
Author and opinionated walrus
Marshal
Joined: Jan 10, 2002
Posts: 50677
|
|
What work have you done so far on it? Or are you expecting someone else to do all the work for you? Ant can most certainly help you manage any sized project. Once you have the build.xml file setup, repeatedly building the project is a piece of cake. Start writing up your build.xml file and let us know what problems you encounter. Btw, it is considered poor practice to put classes in the 'default' package. And it will get you into real troble in the web app environment. [ September 21, 2004: Message edited by: Bear Bibeault ]
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Edward Chen
Ranch Hand
Joined: Dec 23, 2003
Posts: 756
|
|
Actually, I am testing a hibernate project. What I am confusing is package. In the Test.B.java, how can I import A.java ? Of couse, in the Test.B.java, we can not say "import src/A", or "import src.A" because A.java is not packaged into src. How can I work out? package always let me creazy. Thanks
|
 |
Peter Laurinec
Ranch Hand
Joined: Sep 13, 2004
Posts: 52
|
|
|
Well I would advice you to change your .java files location so they are in the proper package mapped directories (e.g. package_nema.class_name)
|
SCJP 1.5 (done, at last)<br /> <br />"If everything seems to be going well you have obviously overlooked something."
|
 |
Bear Bibeault
Author and opinionated walrus
Marshal
Joined: Jan 10, 2002
Posts: 50677
|
|
|
Difficulties such as this is one of the reasons that 'best practice' dictates placing all java classes in a non-default package. Try it, you'll like it.
|
 |
Edward Chen
Ranch Hand
Joined: Dec 23, 2003
Posts: 756
|
|
Originally posted by Bear Bibeault: placing all java classes in a non-default package.
what do you really mean ? I guess, you are saying that we should move the folder "Test" into "src". This is a tranditional way. And I knew how to handle it. Now I am just curious , in my design above, do we have some solution to work out "javac" Thanks
|
 |
Mike Clark
author
Ranch Hand
Joined: Aug 15, 2003
Posts: 83
|
|
Originally posted by Edward Chen: what do you really mean ? I guess, you are saying that we should move the folder "Test" into "src". This is a tranditional way. And I knew how to handle it.
Actually, I think the two top-level directories (src and test) are fine. However, I'd make sure that all Java classes, specifically A.java, are in a package other than the default package. Here's the structure I'd use: Note that the A class, defined in the source file called A.java, would be imported from the B class as: Mike
|
Mike Clark<br />Author of <a href="http://www.amazon.com/exec/obidos/ASIN/0974514039/ref=jranch-20" target="_blank" rel="nofollow">Pragmatic Project Automation</a>
|
 |
Sonny Pondrom
Ranch Hand
Joined: Jun 05, 2001
Posts: 128
|
|
And then the import for C.java would be: What if a C field or method is protected? How can you assert that the method is working correctly, if you can not use it in the Test package? [ September 21, 2004: Message edited by: Sonny Pondrom ]
|
 |
Mike Clark
author
Ranch Hand
Joined: Aug 15, 2003
Posts: 83
|
|
Originally posted by Sonny Pondrom: What if a C field or method is protected? How can you assert that the method is working correctly, if you can not use it in the Test package?
The test case for the class C, which is in the src/com/xyz/util directory, would reside in the test/com/xyz/util package. That is, the 'test' directory mirrors the package hierarchy in the 'src' directory. That way the test case for C can call protected methods on the class C, even though they span different directory trees. Is that what you meant? Mike
|
 |
somkiat puisungnoen
Ranch Hand
Joined: Jul 04, 2003
Posts: 1312
|
|
Originally posted by Edward Chen: In the above project, Test.B.java use A.java object and Util.C.java object. How can I write build.xml file to compile / run Test.B.java ? Here, A.java is a plain file, not belong to any package. Test.B.java is packaged into Test. Util.C.java is packaged into Util which is located in src directry. Thanks
Build.xml
|
SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 23395
|
|
|
Because no one seems to have stated this explicitly: as of J2SDK 1.4, javac no longer supports the importing of a class from the default package into a compilation unit in a named package -- i.e., it's impossible to compile Test.B.java using javac, regardless of what you do with Ant.
|
[Jess in Action][AskingGoodQuestions]
|
 |
somkiat puisungnoen
Ranch Hand
Joined: Jul 04, 2003
Posts: 1312
|
|
Originally posted by Ernest Friedman-Hill: Because no one seems to have stated this explicitly: as of J2SDK 1.4, javac no longer supports the importing of a class from the default package into a compilation unit in a named package -- i.e., it's impossible to compile Test.B.java using javac, regardless of what you do with Ant.
Why not support ?? you can set CLASSPATH env to your classes. Example c:/test/classes -> keep all classes c:/test/src -> keep java source Compile set p=c:/test/classes set CLASSPATH=.;%p%;%CLASSPATH% cd c:/test/src ..... javac -d %p% yourfile.java This will help you.
|
 |
 |
|
|
subject: package problem -- ant ?
|
|
|