aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes File hierarchy vs Package hierarchy in Eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "File hierarchy vs Package hierarchy in Eclipse" Watch "File hierarchy vs Package hierarchy in Eclipse" New topic
Author

File hierarchy vs Package hierarchy in Eclipse

Michael Petrovich
Greenhorn

Joined: Sep 06, 2011
Posts: 16

Hi!

I work with eclipse.

Let assume I have such class:


that is located in ~/MyProject/src/com/hierarchy

Is that possible to avoid compilation errors in IDE for A-class (like The declared package "com.coderanch.hierarchy" does not match the expected package "com.hierarchy")

I've tried to search some answer in Java Build Path on properties for Project Properties. But I failed. Maybe some body can help with this staff?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16308
    
  22

It is a requirement in Java that the components of a package name and its filesystem path relative to the source root be identical. Not only identical as far as names go, but identical as far as the capitalization of the names of the path components.

So, simply speaking, you cannot put a "com.coderanch.hierarchy" in a "com/hierarchy". It isn't an Eclipse limitation, it's a Java restriction.


Customer surveys are for companies who didn't pay proper attention to begin with.
Michael Petrovich
Greenhorn

Joined: Sep 06, 2011
Posts: 16

Could you please provide some link to that limitation? I can't find such in JLS for example.
I can provide link to blog of one experienced Java developer that has an article that denies what you said. But that blog is in Russian so I think it wouldn't be useful for you.
Moreover I have a project with such class hierarchy and it compiles fine with Ant. So I think there is should be such possibility in Eclipse too.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16308
    
  22

I dunno. Do you suppose these folks might be believable? Note Section 7.2.1.

http://java.sun.com/docs/books/jls/third_edition/html/packages.html

Here's a nice tutorial on the topic:

http://www.jarticles.com/package/package_eng.html

I'm not totally incompetent at Russian, but I'll admit that it would be a bit much to reliably read a technical article in it.

Still, remember that not everything on the Internet is true. And some things that were once true are true no longer.

I'd like to see the Ant task that you're compiling with. I do know a few ways to hack the standard rules and I'd like to see which one you're using. Although, come to think of it, I'm not sure a bad package path directive will actually cause a compiler error. Though the resulting class file wouldn't be in the place you'd probably expect.

Still, just because you can break the standard, that doesn't mean that you should. While Eclipse can be persuaded to set aside some of its constraints, those constraints are there because it's bad practice not to obey them, and one of the primary purposes of an IDE is to assist in good practices.
Michael Petrovich
Greenhorn

Joined: Sep 06, 2011
Posts: 16

Yes, I agree that Eclipse can help to avoid bad practices. But for now I have dynamically developed project that was ported from .NET to Java. So some things are go wrong with Java best practices. So I need to manage that staff even if I don't really like that.
As for Ant task... We had NetBeans project and it creates very complex build.xml file with a lot of mess dependencies. Moreover that file was somehow edited by developers for pursuit some build goals. That file has near 1600 lines and completely unreadable. Moreover I don't know (and maybe don't want ) to know how does that staff is working. All I need is to watch on our Continuous Integration that all things go well.
So that is not important what hack is used here. I would like to know how to make that hack with Eclipse.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File hierarchy vs Package hierarchy in Eclipse