Deploying to payara micro provided EJB container after startup

194 views
Skip to first unread message

Jeremy Tidwell

unread,
Feb 14, 2018, 6:34:19 PM2/14/18
to Payara Forum
Hello, everyone :)

I am attempting to use the payara micro provided EJBContainer class in a series of unit tests. I am having an issue deploying some of my project artifacts. 

The artifacts in question have a handful of dependencies between each other that makes establishing a deploy order necessary. Unfortunately, when I pass in the list of artifacts in the MODULES server properties when I start the EJBContainer, there's no way to guarantee that the dependencies are deployed in that order.

So what I'm looking to do is deploy the primary artifact to the EJBContainer using the MODULES property, then use the Payara API (or some other method) to deploy the remaining artifacts, after the container has bootstrapped.

Is this possible?

Steve Millidge

unread,
Feb 19, 2018, 11:31:40 AM2/19/18
to Payara Forum
How are you deploying these modules?
Deployment order in Payara Micro should be the order of --deploy on the command line.
Alternatively if you are deploying programmatically you can deploy after the server has booted using the deploy api and each should be deployed in order.

Jeremy Tidwell

unread,
Feb 20, 2018, 7:43:05 PM2/20/18
to Payara Forum
I am deploying programatically. I'd love to use the deploy API, but the payara doc has no practical examples or payload specs that I can find.

Steve Millidge

unread,
Feb 21, 2018, 5:28:15 AM2/21/18
to Payara Forum
Can you show some code snippets of what you are doing?

Jeremy Tidwell

unread,
Feb 22, 2018, 8:21:13 PM2/22/18
to Payara Forum
Sure!  Here's where I build the MODULES property:

ArrayList<File> files = new ArrayList<>();



String path = "..".concat(File.separator.concat("main project").concat(File.separator).concat("target").concat(File.separator));
String artifact = "main project-".concat(VERSION).concat("-SNAPSHOT.ear");
files
.add(new File(path.concat(artifact)));


path
= "..".concat(File.separator.concat("dependent project").concat(File.separator).concat("target").concat(File.separator));

artifact
= "dependent project-".concat(VERSION).concat("-SNAPSHOT-with-jar-dependencies.jar");
files
.add(new File(path.concat(artifact)));


path
= "..".concat(File.separator.concat("independent project").concat(File.separator).concat("target").concat(File.separator));
artifact
= "independent project-".concat(VERSION).concat("-SNAPSHOT-with-jar-dependencies.jar");
files
.add(new File(path.concat(artifact)));


File[] artifacts = new File[files.size()];
artifacts
= files.toArray(artifacts);

And then I pass it in as a property to the EJBContainer call:


ejbProperties
.put("org.glassfish.ejb.embedded.glassfish.installation.root", installationRoot);
ejbProperties
.put("org.glassfish.ejb.embedded.glassfish.instance.root", instanceRoot);
ejbProperties
.put("org.glassfish.ejb.embedded.glassfish.configuration.file", configFile);
ejbProperties
.put("org.glassfish.ejb.embedded.glassfish.instance.reuse", "true");
ejbProperties
.put("org.glassfish.ejb.embedded.keep-temporary-files", "true");
// Add the modules from above here
ejbProperties
.put(EJBContainer.MODULES, classFiles);

container
= EJBContainer.createEJBContainer(ejbProperties);

Jeremy Tidwell

unread,
Mar 2, 2018, 3:36:34 PM3/2/18
to Payara Forum
Does anyone have a link to documentation on how to use the payara micro deployment API?  I can't find it anywhere.

Ondro Mihályi

unread,
Mar 3, 2018, 7:05:48 PM3/3/18
to Payara Forum
Hi,

Using Payara Micro API is documented in the main documentation at https://docs.payara.fish/documentation/payara-micro/payara-micro.html

In the part about Payara Micro, you can find a section called "Deploying Applications Programmatically" which contains pages about using the API to deploy applications in various ways, with code examples.

To use the API, you need to add payara-micro as a compile-time dependency to your project (in maven projects this would be a dependency with scope "provided"). This is described in the section called "Maven Support" (https://docs.payara.fish/documentation/payara-micro/maven/maven.html) where you can find payara-micro artifact coordinates.

The rest of the Payara Micro API is explained in other sections in the Payara Micro appendix, but it may not be completely up to date. Javadoc is at http://static.javadoc.io/fish.payara.extras/payara-micro/4.1.2.181/fish/payara/micro/package-summary.html.

There's an example project in the Payara Examples repository that shows how to deploy all applications in a directory with a setDeploymentDir method, which is one of the options to deploy applications programmatically: https://github.com/payara/Payara-Examples/blob/8cb67f57862d31609935b18ae5763ff8f3849d92/Payara-Micro/deployment-example/src/main/java/BootAndDeploy.java#L31

I hope that helps ;-)
Ondro

Jeremy Tidwell

unread,
Mar 16, 2018, 8:38:35 PM3/16/18
to Payara Forum
I cannot use payara micro in that fashion, as my organization doesn't support a version that allows me to set libraries for it.  I have to use the EJBContainer provided by payara for the time being.
Reply all
Reply to author
Forward
0 new messages