Using Payara Embedded & Payara Micro with Maven
Originally published on 15 May 2015
Last updated on 19 Mar 2020
First off, open the POM.xml file of the module or project that needs to use Payara Embedded or Micro, and add one of the embedded distributions as a dependency:
Payara Embedded All
<dependency>
<groupId>fish.payara.extras</groupId>
<artifactId>payara-embedded-all</artifactId>
<version>5.201</version>
<type>jar</type>
</dependency>
Payara Embedded Web
<dependency>
<groupId>fish.payara.extras</groupId>
<artifactId>payara-embedded-web</artifactId>
<version>5.201</version>
<type>jar</type>
</dependency>
Payara Micro
<dependency>
<groupId>fish.payara.extras</groupId>
<artifactId>payara-micro</artifactId>
<version>5.201</version>
<type>jar</type>
</dependency>
And that’s about it! With one of the above added as a dependency, you can now begin using Payara embedded in your application and project. For example, the following code will create and start an embedded Payara server, with the HTTP and HTTPS listener set to ports 8083 and 8184 respectively:
import java.util.logging.Level;
import java.util.logging.Logger;
import org.glassfish.embeddable.BootstrapProperties;
import org.glassfish.embeddable.GlassFishRuntime;
import org.glassfish.embeddable.GlassFish;
import org.glassfish.embeddable.GlassFishException;
import org.glassfish.embeddable.GlassFishProperties;
/**
* Basic Example showing how to programmatically create, edit, and
* start an embedded Payara Server.
*
* @author Andrew Pielage
*/
public class EmbeddedExample
{
public static void main(String [] args)
{
try
{
BootstrapProperties bootstrap = new BootstrapProperties();
GlassFishRuntime runtime = GlassFishRuntime.bootstrap(bootstrap);
GlassFishProperties glassfishProperties = new GlassFishProperties();
glassfishProperties.setPort("http-listener", 8083);
glassfishProperties.setPort("https-listener", 8184);
GlassFish glassfish = runtime.newGlassFish(glassfishProperties);
glassfish.start();
}
catch (GlassFishException ex)
{
Logger.getLogger(EmbeddedExample.class.getName()).log(Level.SEVERE,
null, ex);
}
}
}
Note: You won’t be able to drop in Payara Micro quite like this; Payara Micro is based on the GlassFish Web distribution, and using it programmatically works a little differently (See Steve's introductory blog for an example).
That’s it for now, if you need further help with using Payara Embedded, you can find the GlassFish guide for using the embedded server here: http://docs.oracle.com/cd/E26576_01/doc.312/e24932/embedded-server-guide.htm#GSESG00001
If you are needing some help with the new Payara Micro, don’t worry, we should have some documentation for it up on our GitHub wiki soon; we’ll let you know when. As always, let us know if there’s any killer feature, improvement, or fix that you want to make it into Payara.
Related Posts
The Payara Monthly Catch - October 2024
Published on 30 Oct 2024
by Chiara Civardi
0 Comments
Can You Futureproof Your Enterprise Java Apps or Are They Doomed to Fall Behind?
Published on 16 Oct 2024
by Chiara Civardi
0 Comments