Discussion:
can't rename default package?
PatBateman
2011-05-30 08:12:20 UTC
Permalink
Why can't I rename the default package? How do I get around this in my code? I need to reference the default package.
Tushar Joshi
2011-05-31 03:39:47 UTC
Permalink
Post by PatBateman
Why can't I rename the default package? How do I get around this in my
code? I need to reference the default package.
Hi,

It is advised that a java project should have proper package hierarchy. We
should not have classes in default package.

The default package in NetBeans is just a placeholder to show all the
classes which are not kept in any package. We cannot import (reference)
classes in default package into classes inside packages. It is a compile
time error doing so. [1]

You can somehow do this anyway by using reflection, but if you just want to
use those classes it is advisable to move them to a package. NetBeans IDE
has good support of moving classes to another package. The steps will be to
create a new package of your desired name and then move the desired class
from the default package into that newly created package.

Once you have the class in a package it can be imported (referenced) in any
class inside another package.

[1]
http://stackoverflow.com/questions/2193226/how-to-import-a-class-from-default-package
--
with regards
Tushar


Tushar Joshi, Nagpur: http://www.tusharvjoshi.com

* MCSD_NET C#, SCJP, RHCE, ZCE, PMP

* Principal Architect: http://www.persistentsys.com
* NetBeans Dream Team Member: http://dreamteam.netbeans.org
* DZone Most Valued Blogger: http://netbeanside61.blogspot.com
* Java User Group Nagpur Leader: http://www.jugnagpur.com

* LinkedIn: http://www.linkedin.com/in/tusharvjoshi
Glom
2011-06-01 11:26:15 UTC
Permalink
Just create a new package and drag and drop the the files into their from the default. Netbeans will ask about refactoring because it wants to update everyone's package name. It usually works fine except it often ends up with files importing its own package. But that's not a major problem.
Continue reading on narkive:
Loading...