• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Eclipse and package statement

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my project, I have some Java classes where the declared package statement in the classes does not match the path to the source file. I'm well aware of that, and I have good reasons for it, so I'm not about to change it.
Eclipse sees this as an error, and complains that "The declared package does not match the expected package". How do I tell Eclipse to accept my package statement as it is? The Java compiler has no problems with it.
Thanks
Regards
Anders
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Anders Olsen:
In my project, I have some Java classes where the declared package statement in the classes does not match the path to the source file. I'm well aware of that, and I have good reasons for it, so I'm not about to change it.
Eclipse sees this as an error, and complains that "The declared package does not match the expected package". How do I tell Eclipse to accept my package statement as it is? The Java compiler has no problems with it.
Thanks
Regards
Anders


Eclipse uses directories to represent package paths to source in the same way that they are used to represent package paths to classes - in some cases the source and class files can be in the same directory.
So Class.java in the "com.whatever.stuff" packages will be in the directory "com/whatever/stuff". Which makes sense, at least to me. It certainly seems to be the common way of doing things.
So that's Eclipse's "good reason for this" - what's yours?
Simes.
 
Anders Olsen
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your reply Simes.
Well, I guess you can argue how good my reason is. I'm part of a large Java development project. We have previously been using Emacs, but now I would like to try Eclipse. I have been using Eclipse at home, so I am not completely new to Eclipse.
In our project we have different teams working on different parts of the project. Each project works on different parts of the package hierachy. Out project has made a small tool that should be available to all the other teams just by starting: "java Tool". But since our team is supposed to place out files in our package hierarchy, we have made a package called dk.project.outteam.tool where the classfiles for the tool is located. As I said, the Java compiler accepts this.
Is this a good way of doing things? Well, perhaps not. It is unfortunately too late to do anything about it, so now I just need to get Eclipse to accept things as they are. If that is possible
 
Simes Brown
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know if there's a way to get Eclipse to accept file structures differently to the ones it usually uses. As a workaround if you're on Unix or a unix-alike you could create the dk/project/outteam hierarchy and have the tool folder be a symbolic link to your dk.project.outteam.tool folder.
If not, it might be possible to work something with Eclipse's import and export features, but that would probably become something of a chore.
Simes.
 
Anders Olsen
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm on Windows 2000.
Our package structure is part of CVS modules, so I don't want to start exporting and importing different things. I was hoping that I could make Eclipse ignore the package statements, but I can't find anything under Properties, Java, Compiler.
Regards Anders
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not familiar with CVS and the restrictions that it might place on you. We use ClearCase and our directory structure does not match our package structures. The way I deal with this is to create source folders in eclipse and then create the a package of the appropriate name (com.foo.pack...) in that source folder and then import from the file-system into the package (since ClearCase gives me a file-system view).
I check files in and out via clearcase, outside of eclipse. When I'm ready to do a full system build, I export the files I modified back to the clearcase view's filesystem.
It's a bit kludgy, but it works.
 
Anders Olsen
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The package is part of a CVS module, and with Eclipse you can't check out part of a module from CVS. Actually, you don't have much controll of how you check out a module, but that is an entire different story.
When I check out my module, I also get the problematic package.
I have found another solution. All the files in the directory have no package statement, so in my Java project, I have added a source path to the directory, and setup an exclusion filter on the path it is nested in. In this way, Eclipse accepts the default package, and everything seems to work. This solution however only works because no files in the directory have package statements.
Regards
Anders
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Anders Olsen:
This solution however only works because no files in the directory have package statements.


Be very careful here. AFAIK if this is going to be a web project deployed in a servlet container such as tomcat, and if classes in the files that you mention need to be accessible to JSP pages then you are going to run into huge problems.
Rgds,
Tarun
 
Anders Olsen
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the warning.
It is a J2SE project (perhaps later some J2ME), so we don't have any JSP or other J2EE things.
If I could change the way the package structure was, I think I would do that, but it is to late in the project.
Regards
Anders
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure how far off your 'non-standard directory' source files are.
How about making two seperate projects in Eclipse, one large one for the entire application, and one smaller one for the part of your application that your team is responsible for. Then you can add the larger one to the classpath of the smaller one. And now you can keep the files that your team changes in a seperate directory structure.
This should work particularly well if all the 'non standard directory' source files are in the anonymous package (i.e., none have a 'package' statement).
 
The City calls upon her steadfast protectors. Now for a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic