logo
21.2
search
No matching documents found.
list
search
No matching documents found.
logo
Please be aware that there is newer version of documentation available for Webswing. Documentation 24.2

NetBeans

NetBeans Platform Application setup

In general, NetBeans platform applications are configured the same way as regular Swing applications. You can use Admin Console or edit the webswing.config file manually. There are however a few specific settings that are necessary for running NetBeans in Webswing.

Simple NetBeans Platform application setup

First is a minimalistic NetBeans platform demonstration bootstrapped with simple main class, not using the standard NetBeans packaging, which use shell script or exe file for bootstrapping the application. Here is how it's configured in Webswing:

{
    "name" : "NetBeans Platform",
    "mainClass" : "org.webswing.demo.NbMain",
    "classPathEntries" : [ "nbplatform.jar", "lib/*.jar" ],
    "vmArgs" : "-Dorg.netbeans.log.startup=print -DTopSecurityManager.disable=true",
    // rest of the JSON omitted
}  

The most important part here is the -DTopSecurityManager.disable=true property in vmArgs. This tells NetBeans to disable its default Java Security Manager, which would otherwise prevent Webswing from doing its magic.

We are using our own main class to bootstrap the NetBeans application. This is the only class located in nbplatform.jar. The lib folder contains the smallest subset of NetBeans libraries for starting the NB platform window. This is the content of main class:

package org.webswing.demo;

public class NbMain {
    public static void main(String[] args) throws Exception {
        org.netbeans.core.startup.Main.main(args);
    }
} 

NetBeans platform window

NetBeans IDE setup

The second example is the full blown NetBeans IDE. The NetBeans installation itself is not included in the Webswing distribution, for obvious reasons. So before running it, you will need to set up the homeDir property in webswing.config file to point to your NetBeans installation.

Here is the snippet of the relevant part of Webswing configuration for NetBeans IDE:

 {
    "name" : "NetBeans IDE (set homeDir)",
    "mainClass" : "org.netbeans.Main",
    "classPathEntries" : [ "platform/*/*.jar/","platform/lib/*/*.jar" ],
    "vmArgs" : "-Dnetbeans.user=${user.dir}/tmp/netbeans/${user} -Dnetbeans.home=platform  -Dorg.netbeans.log.startup=print -DTopSecurityManager.disable=true -Dnetbeans.dirs=\"platform;nb;ergonomics;ide;extide;java;apisupport;webcommon;websvccommon;enterprise;mobility;profiler;python;php;identity;harness;cnd;dlight;groovy;extra;javacard;javafx\"",
    "args" : "",
    "homeDir" : "c:/Program Files/NetBeans 8.0.2",
    //rest of configuration omitted...
}

Note: this setup is for unmodified folder structure of NetBeans IDE.

This configuration mimics the shell script that initializes NetBeans IDE. Similar setup can be used for NetBeans platform applications that use the standard NetBeans packaging.

Here are the most important parts of the setup explained.

mainClass : "org.netbeans.Main"

The main class for NetBeans will always be the above in case you are using the standard way of packaging.

"classPathEntries" : [ "platform/lib/*.jar","platform/lib/*/*.jar" ]

These folders contain the NetBeans libraries that are necessary for bootstrapping the NB application. Always use only these folders. NetBeans will load the rest of libraries by its plugin system.

"vmArgs" : "-Dnetbeans.home=platform"

This setting tells NetBeans where to look for platform libraries and resources.

"vmArgs" : "-Dnetbeans.user=${user.dir}/tmp/netbeans/${user}"

NetBeans create its user session files in a folder specified by this setting. It is good to have it as different for each user, therefore, we include the Webswing specific variable ${user} to the path.

"vmArgs" : "-DTopSecurityManager.disable=true"

As noted above this will allow Webswing to do the magic.

"vmArgs" : "-Dnetbeans.dirs = \"platform;nb;ergonomics;ide;extide;java;apisupport...

This property will tell NetBeans which folders to look into for initializing the plugins. You can use the subset of necessary folders for your use case.

Note: Be careful with the escaped chars like \" in the json configuration. It is recommended to use Admin console to avoid problems with escaping.

Netbeans IDE

Custom NetBeans Platform application - VisualVM

This example illustrates step by step guide to setup VisualVM in Webswing.

  1. Download and unzip VisualVM distribution package.

  2. Start the VisualVM application executable located in the bin folder from command line with an additional argument -J-Dnetbeans.logger.console=true.

  3. Console output will provide you with everything needed as vmArgs, classpath entries, and main class. From the output re-create a java command using the pattern below and test if this command will successfully launch your application.

    java -J-Dnetbeans.logger.console=true <java arguments> -cp <class path entries> org.netbeans.Main
    
  1. If your app has started correctly you can take the the relevant parts to Webswing configuration. For Webswing you also need to add -DTopSecurityManager.disable=true into the vmArgs config field. First try running everything with absolute paths.

  2. If everything is working then you can replace absolute paths by relative paths and add variables , for example, replace the java path with ${java.home}

    Here is the snippet of the relevant part of Webswing configuration for VisualVM app after mentioned steps are done.

"/visualvm" : {
    "path" : "/visualvm",
    "security" : {
      "module" : "INHERITED",
      "config" : { },
      "classPath" : [ ]
    },
    "icon" : "icon.png",
    "webFolder" : "",
    "swingConfig" : {
      "jreExecutable" : "${java.home}/bin/java",
      "javaVersion" : "${java.version}",
      "vmArgs" : "-J-Dnetbeans.logger.console=true -DTopSecurityManager.disable=true -Xms24m -Xmx768m -Dnetbeans.accept_license_class=org.graalvm.visualvm.modules.startup.AcceptLicense -Dnetbeans.importclass=org.graalvm.visualvm.modules.startup.ImportSettings -Dsun.jvmstat.perdata.syncWaitMs=10000 -Dsun.java2d.noddraw=true -Dsun.java2d.d3d=false -Dorg.netbeans.core.TimeableEventQueue.quantum=360000 -Dpolyglot.js.nashorn-compat=true -Dsun.misc.URLClassPath.disableJarChecking=true -Djdk.attach.allowAttachSelf=true -Dorg.openide.util.ImageUtilities.level=950 --add-exports=java.desktop/sun.awt=ALL-UNNAMED --add-exports=jdk.internal.jvmstat/sun.jvmstat.monitor.event=ALL-UNNAMED --add-exports=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED --add-exports=java.desktop/sun.swing=ALL-UNNAMED --add-exports=jdk.attach/sun.tools.attach=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.lang.ref=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.desktop/javax.swing=ALL-UNNAMED --add-opens=java.desktop/javax.swing.plaf.basic=ALL-UNNAMED -XX:+IgnoreUnrecognizedVMOptions -Dnetbeans.logger.console=true -Djdk.home=\"${java.home}\" -Dnetbeans.home=\"${webswing.rootDir}/apps/visualvm/platform\" -Dnetbeans.user=\"<User-Directory>\" -Dnetbeans.default_userdir_root=\"<User-Directory>/VisualVM\" -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=\"<User-Directory>/VisualVM/2.1.1/var/log/heapdump.hprof\" -Dsun.awt.keepWorkingSetOnMinimize=true -Dnetbeans.dirs=\"${webswing.rootDir}/apps/visualvm/visualvm\"",
      "classPathEntries" : [ "platform/lib/*.jar","platform/core/*.jar","visualvm/core/*.jar","visualvm/core/*/*.jar" ],
      "theme" : "Murrine",
      "swingSessionTimeout" : 300,
      "antiAliasText" : true,
      "isolatedFs" : true,
      "debug" : true,
      "directdraw" : true,
      "allowDelete" : true,
      "allowDownload" : true,
      "allowAutoDownload" : true,
      "allowUpload" : true,
      "allowJsLink" : true,
      "fontConfig" : { },
      "launcherType" : "Desktop",
      "launcherConfig" : {
        "mainClass" : "org.netbeans.Main"
      },
      "homeDir" : "${webswing.rootDir}/apps/visualvm"
    },
    "maxClients" : 1,
    "allowStealSession" : true,
    "name" : "VisualVM",
    "sessionMode" : "CONTINUE_FOR_BROWSER",
    "uploadMaxSize" : 5,
    "webHomeDir" : "${webswing.rootDir}/apps/visualvm"
  },

Please, replace <User-Directory> in with your appdata directory. For example C:\\Users\\user\\AppData\\Roaming.