0

I use NetBeans to create Payara Server normal Java Web projects. But now I would like to run a new Java Web project using Payara Micro. Today, I'm using a "main class" and I need to open this class, type Shift+F6 to run, but it would be great if normal F6 would work.

Here is my "main":

public class Run {

  public static void main(String[] args) {
    try {
      PayaraMicro.getInstance()
              .addDeployment("/sistemas/sitesat2mod/build/web/")
              .setHttpPort(8080)
              .setHttpAutoBind(true)
              .bootstrap();
    } catch (BootstrapException e) {
      e.printStackTrace();
    }
  }

}

2 Answers2

2

There's no direct support for Payara Micro in Netbeans to run web applications yet.

The simplest solution is to open the build.xml configuration file and insert the followin snippet right below the line with the import statement:

<target name="-run-deploy-nb"/>
<target name="run" depends="run-deploy">
    <java jar="/path/to/payara-micro.jar">
        <jvmarg value="-Xmx256m">
        <arg value="--deploy"/>
        <arg value="${dist.war}"/>
        <arg value="--port"/>
        <arg value="8080"/>
        <arg value="--autobindhttp"/>
    </java>
</target>

Instead of /path/to/payara-micro.jar specify absolute path to your payara-micro.jar, or if payara-micro.jar is inside your project dir in a lib directory, you may specify the relative path with the basedir variable like this:

<java jar="${basedir}/lib/payara-micro.jar">

After you save the build.xml file, you can press F6 and your application will be deployed with Payara Micro. You should then configure command line parameters in build.xml instead of your Run Java class (you should delete your Run class because it won't be used)

Edit:

If you want to restart (redeploy) your application, you have to press Ctrl + Shift + Del to stop the running application before pressing F6 to run the new version. So each time you want to redeploy, first press Ctrl + Shift + Del and then F6.

OndroMih
  • 7,280
  • 1
  • 26
  • 44
  • Your solution works fine for first F6. But if I already have Payara Micro running and type a new F6 because I change some logic in my app, it starts again Payara Micro. I would like the same behaviour as a Payara Server+NetBeans, that restarts the server and redeploys the app. – Edilmar Alves Dec 21 '17 at 17:54
  • Payara Micro doesn't work that way. You have to stop the previous application with the red square button and then press F6. It works as any plain Java application, with Payara Micro you're no longer deploying to the same server. – OndroMih Dec 27 '17 at 20:22
  • Then, I think using these config from build file or my Run class is almost the same thing. Is not there any way to configure build and kill the actual process before a new F6? – Edilmar Alves Dec 29 '17 at 12:33
  • Using the config from build file helps because you don't need to switch to your helper class in the editor before you press F6. But Payara Micro runs as a plain Java application and Netbeans doesn't support stopping the previous execution automatically before a new execution. You have to press Ctrl + Shift + Del to stop the application before you press F6 to run it again. A new version of Payara Netbeans plugin is going to support running apps with Payara Micro and it should do you what you want with a single F6 button. – OndroMih Dec 30 '17 at 13:46
1

An alternative approach is to restructure your project to use Maven build system, which is directly supported by Netbeans without any plugins.

There's Payara Micro maven plugin which can be added to the build configuration and this plugin can start and stop Payara Micro. If you configure it to first stop a running instance and then start a new instance, it will restart Payara Micro in a single action.

Most of the new projects these days are based on maven because it's a standard way to structure and build projects and it's supported by many IDE's and even from command line, whereas traditional Ant-based Netbeans projects aren't supported by other IDE's automatically.

OndroMih
  • 7,280
  • 1
  • 26
  • 44