Geertjan's Blog

  • August 3, 2010

Figuring Out the Classpath for NetBeans RCP Applications in IntelliJ IDEA

Geertjan Wielenga
Product Manager
The biggest challenge in the IntelliJ IDEA plugin for NetBeans RCP development is... getting the classpath right. And providing tools for IntelliJ IDEA for users of the plugin to modify the classpath specifically for the NetBeans Platform.

Here's the first stage—making the JARs in the NetBeans Platform available to IntelliJ IDEA so that the user can add them as a dependency to their project. The result of the code that follows is that the folder containing the modules is registered as a JAR directory in the Libraries tab of the Project Structure dialog:

Here's the code:

//Path specified in New Project wizard by user:
String netBeansPlatformPath = facetEditor.getPath();
//The above as a VirtualFile:
VirtualFile path = LocalFileSystem.getInstance().findFileByPath(netBeansPlatformPath);
//Get the library registry:
LibraryTablesRegistrar libTablesRegistrar = LibraryTablesRegistrar.getInstance();
//Get the table of project libraries (pass empty parameter if you want global libraries instead):
LibraryTable libraryTable = libTablesRegistrar.getLibraryTable(module.getProject());
//Get the model of the library table:
LibraryTable.ModifiableModel libTableModel = libraryTable.getModifiableModel();
//Create a library in the model:
Library netBeansLibrary = libTableModel.createLibrary("NetBeans RCP");
//Get the model of the library:
Library.ModifiableModel libraryModel = netBeansLibrary.getModifiableModel();
//Create a string pointing to the NetBeans Platform modules:
String url = VfsUtil.getUrlForLibraryRoot(new File(netBeansPlatformPath + "/platform/modules"));
//Add a JAR directory to the library model:
libraryModel.addJarDirectory(url, false);
//Commit the library model:
//Commit the library table model:

Now the same dialog above can be used to set the library (containing all the JARs) as a dependency of the project or module, as shown here:

Next steps involve figuring out how to automatically attach the new library as a dependency of the project. But more important is figuring out how to, ultimately, register module dependencies in the manifest file of the modules within the application, in so far as those modules are dependent on those dependencies. That's handled automatically by NetBeans IDE and is the main feature that I don't know how to implement, yet, in IntelliJ IDEA.

Join the discussion

Comments ( 3 )
  • Jesse Glick Tuesday, August 3, 2010

    This all seems like a waste of time. Wouldn't it be easier and more effective to create the Platform app using Maven, which IntelliJ would then presumably already know how to open and work with?

  • Geertjan Wielenga Tuesday, August 3, 2010

    Not everyone likes Maven.

  • Geertjan Wielenga Tuesday, August 3, 2010

    Here's an earlier article re Maven and NetBeans and IntelliJ:


    Still, Maven isn't everybody's cup of coffee.

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.