JN_newbie
JN_newbie

Reputation: 6072

Auto deploy changed java code in Maven, Eclipse, Glassfish

I am new very much new to maven and spring technologies. I want to know how can we auto deploy the java server code without rebuilding the maven or without restarting the glass fish server? Currently I have to restart the server if any change I do in java code. I have also use one option in Eclipse to "Automatically publish when resources change" but no use.

Upvotes: 0

Views: 1097

Answers (2)

Ondro Mihályi
Ondro Mihályi

Reputation: 7710

The recent version of HotSwap Agent works very well for me with Eclipse and Payara Server (server derived from and compatible with GlasFish).

It's free and opensource and supports Java 8, including lambdas. It supports reloading of resources in a webapp running on GlassFish/Payara, including JAX-RS annotations, CDI bean definitions etc., without restarting whole application.

The only drawback is that you need to install the DCEVM plugin into the JDK, which has to be activated by a command line argument -XXaltjvm=dcevm. But this isn't intrusive and doesn't affect your JDK if you avoid the argument - you can activate it just for GlassFish/Payara Server when you add it to the JVM options in the domain configuration. When adding the -XXaltjvm=dcevm option, you also have to remove -client and -server option, because they take precedence.

So, essentially these steps are needed with the recent version of HotSwap agent and practically with any version of GlassFish and Payara Server:

  • install DCEVM as altvm into the JDK (run the installer with admin rights)
  • copy the hotswap-agent.jar into lib/ext in your domain directory
  • add the following arguments as JVM options in your domain configuration: -XXaltjvm=dcevm -javaagent:/path/to/hotswap-agent.jar
  • run the server in debug mode from your IDE
    • in Eclipse, all works out of the box, just avoid using the Publish button for the server. Check that "Never Publish automatically" is checked in the server Overview, when you double click on the server in the Servers view
    • in Netbeans, you need to disable "Deploy on save" in project configuration and enable "Apply code changes after save" in global Java Debugger options

There is some information in this Payara issue, although it isn't an easy to follow guide. Some more info in this HotSwap issue.

Upvotes: 0

Simon Hylander
Simon Hylander

Reputation: 43

You may want to take a look at JRebel, it reloads changes made to your code instantly without having to restart your application server.

Upvotes: 2

Related Questions