Click to See Complete Forum and Search --> : Java package declaration and eclipse


ravalox
06-29-2005, 10:14 AM
I have a bit of an odd question, I am trying to pull a poorly architected
old project into the eclipse environment. The principal hang up here is
that the file structure of this project does not correlate with the package
declarations. I have been told that I cannot changed the package
declaration (or the files at all really) so I can't simply change their
package declarations. In it's old environment and indeed in older java
setups, you could declare a java file to be in a package and have it sitting
in a directory with the understanding that when it was built into a .class
file it would be made be put in the appropriate package directory within the
Classes directory. An example: class X is declared as a member of package
com.filesinterface but resides in a director <projectdir>/Otherfiles/X.java
but when X.java is compiled it creates the file:
<projectdir>/Classes/com/filesinterface/X.class. This works in Versata(the
ide it was originally created in) but in eclipse it of course delivers the
error:
The declared package does not match the expected package X



Is there a way to insruct Eclipse to not try to correlate the physical file
structure with the package declaration?

Khalid Ali
06-29-2005, 05:08 PM
don't think so, here is why .
Any java compiler will have to throw an error if a file is not in a package structure where it says it is. To inactivate such behavior means to mess with core java rules.
can u not compile that class in a separate project and then put it in the folder where it should be at?

ravalox
06-30-2005, 10:12 AM
The files compile where they are located in Versata Studio, the package declarations take them to the corresponding directory in the Classes folder. I went and looked at the packages principles on Sun's web page and it said the package declarations are instructions to the java compiler on where to put the class files. It doesn't claim that the .java files have to reside in the file structure in directories that match, just that that's where the classes go. If I am wrong about this I'd like to see something about it. I like eclipse and I think it's a good idea to obey those naming conventions, but it may mean that I cannot import this project.

Khalid Ali
06-30-2005, 08:36 PM
.... I like eclipse and I think it's a good idea to obey those naming conventions, but it may mean that I cannot import this project.

I 'm afraid so..:-(

steverar
07-07-2005, 10:01 PM
By default, Eclipse takes the project root directory as a source folder.
So, subdirectories are seen as package elements, making it think your code
is in a package project.mdl.java.Prog. This doesn't match the package
declared *inside* the source file (presumably, your code is in the default
package - no package declaration at all). Right click the project folder,
open its properties and tell Eclipse the correct directory to use as the
source folder. Under Java Build Path, you can specify which libraries your
code needs.
HTH,
Michiel

Found this at http://www.javakb.com/Uwe/Forum.aspx/java-programmer/7832/Java-Compilation-error-using-Eclipse

In short, when you create a "simple" project using the wizards Eclipse puts the code in a default package; not exactly the project/package name you used.

Either get rid of the package declaration or create a new package in the project matching the code package entry.

smefferd
08-17-2005, 04:48 PM
I too am having the same problem with a Versata project in Eclipse. You should know, however, that this project compiles fine with IntelliJ IDEA.There should be a way to do it in Eclipse.