aspose file tools
The moose likes Beginning Java and the fly likes question on package naming vs. directories Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "question on package naming vs. directories" Watch "question on package naming vs. directories" New topic
Author

question on package naming vs. directories

Fritz Urling
Greenhorn

Joined: Jan 09, 2006
Posts: 13
I admit that I am weak when it comes to packages. But I always thought that the package name in the .java file had to match your directory structure.

We have some files with the following:



but the directory structure is



I'm using eclipse to do my builds, and it complains that the package declaration doesn't match the expected package name.

However, ANT builds things just fine. When we open up the package, we see in there both a lpname directory with the .class files, and the longpackagename directory with the .java files.

Does Eclipse enforce something that ANT doesn't? do we have ANT configured wrong? Or do I just have a basic flaw in my understanding of how the world works???
Jaime M. Tovar
Ranch Hand

Joined: Mar 28, 2005
Posts: 133
As far as i know packages and directories must match in order to compile and i think this does not depends of the ide but is the way javac works.


She will remember your heart when men are fairy tales in books written by rabbits.<br /> As long as there is duct tape... there is also hope.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24057
    
  13

Hi,

Welcome to JavaRanch!

The "rule" about packages and paths isn't really a rule; the Java Language Specification suggests that some implementations may require this, but it's not set in stone. In general, it helps, and the default behavior of many tools is to assume that's how things are laid out. But with the proper command-line flags, many Java compilers can find source and class files that aren't stored this way. Ant is just passing the right switches to "javac" so that it can find the files. Eclipse knows where things are, but it's telling you you're doing things in a nonstandard way.

You'll actually have much more of a problem at runtime, though, if your classes are stored in improperly named directories -- most if not all JVMs want things to be stored the recommended way.

In general, it's easiest to just do things the standard way, but it's nice to know that in some situations you can bend javac to your will if needed.


[Jess in Action][AskingGoodQuestions]
Fritz Urling
Greenhorn

Joined: Jan 09, 2006
Posts: 13
thanks. so in the end it's a configuration issue. apparently we have ANT set up to allow it, but not my Eclipse.

We ultimatly changed the package statement to match our directories, to preserve our sanity. it was just odd seeing it work in some places but not others. we were worried it might have been a "tip of the iceberg", but now i think we can all sleep safely.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: question on package naming vs. directories
 
Similar Threads
invoking java task from ant
how to deploy vaj apllication on a tomcat server
Using Eclipse as a Java editor
automation project creation
Eclipse and ANT