How to modify the main Method of a 'NetBeans Platform'-based application?

78 views Asked by At

I am working on a Maven- and 'NetBeans Platform'-based Java desktop application. My use case requires setting a system property as the very first step before anything else happens. I need to do this in the main method, because using a static block in the ModulInstall is too late for my requirements. The challenge I'm facing is that I can't locate the main method in my 'NetBeans Platform'-based Java desktop application.

Can someone guide me on where to find the main method in a 'NetBeans Platform'-based application, or how I can write my own main method for this type of application? I appreciate any insights or solutions to this issue.

2

There are 2 answers

0
Dawid On BEST ANSWER

I successfully resolved my issue with the guidance provided in this post: https://stackoverflow.com/a/12908982/13583700

I utilized a custom main method to set the system property as the initial step, ensuring it precedes any other actions. Afterward, I invoked NetBeans's main method.

0
Joachim Rohde On

I once had a similar problem where the OnStart annotation (source / example) was executed too late.

Since I only had a single NetBeans module I introduced an abstract TopComponent class. Within the constructor I had a synchronized initialization block. Every other TopComponent extended from the abstract class. Since there is no order in which the modules are initialized, the first module that gets loaded initializes the code.

That worked pretty well for me even though I consider it quite hacky.

(At least) Two things you need to consider:

  • you will probably use a flag to indicate if the initialization was already done. Don't use an ordinary boolean rather an AtomicBoolean else your intialization might be invoked several times
  • don't forget to extend from the abstract class if you introduce a new TopComponent