X

Geertjan's Blog

  • October 28, 2006

Playing with Public Packages

Geertjan Wielenga
Product Manager
In the API Versioning panel in the Project Properties dialog box for NetBeans module projects, there is a "Public Packages" checkbox. You can specify that a package is public, which is not the case by default. What effect does this have? Follow the steps below to find out.
  1. Create a module suite project. Set the project name as "MyNewSuite". Click Finish.
  2. Right-click the suite's Modules node. Choose Add New. Type "ModuleA" as the project name. Click Next and Finish.
  3. Repeat the step above, but name the module "ModuleB".
  4. Create an empty class in the org.yourorghere.modulea package created for you in ModuleA. Use the default name "NewClass".
  5. Right-click ModuleA and choose Properties. In the Project Properties dialog box, select "API Versioning". In the "Public Packages" list, select the org.yourorghere.modulea checkbox. Now other modules can use this package. Make sure there's a check mark in the checkbox and then click OK to close the Project Properties dialog box.
  6. Right-click ModuleB and choose Properties. Click Libraries and type "modulea" in the Filter. The "Module" list shows your "ModuleA". Notice in the description that org.yourorghere.modulea.NewClass is listed. This shows you that you can use it in your module, because it belongs to ModuleA's public package. Click OK. Then click OK again to exit the Project Properties dialog box.
  7. In ModuleB, create a new class called "NewClass1", in the main package, which was created for you, called "org.yourorghere.moduleb".
  8. In ModuleB's constructor type this:

    NewClass a = new NewClass();
  9. Place your cursor on the line above. A lightbulb appears. Click on the lightbulb and let the IDE add the import statement for org.yourorghere.modulea.NewClass.

Hurray, you're now using a class belonging to ModuleA in ModuleB. This is how it works, so don't forget to check the "Public Packages" checkbox, if needed, otherwise you won't be able to access classes from one module in another.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha