简体   繁体   中英

How to embed a Wildfly server within an application

I'm building an OSGi application containing (at the moment) only business logic. Since I want my users to interact with my software via browser I'm thinking on trying to add an application server inside my application via commands like:

public void startApplicationServer();
public void stopApplciationServer();
public void deployApp(App appToDeploy);
public void undeployApp(App appToUndeploy);

After some thought, the application server I've chosen is "wildfly 10". However, I'm failing to find any resource allowing me to call wildfly programmatically. My question is do you know a procedure to follow or general steps in order to achieve my goal?

Some info you can find useful to help me:

  1. I've chosen Wildfly becuase it fully support Java EE 7, run on JDK8 and it is released under LGPL (I preferred open source glassfish, but it was release under GPL, hence it would have been mandatory to make the source available. Since (in the future) I would like to make this software commercial, I was forced to discard it);
  2. Maybe some of you may suggest to build my whole application on the application server itself. I prefer not to do so because the web interface may be only one possible User Interface of my application (who knows, maybe in the future I want to switch to another interface, like CLI or desktop-like);
  3. I've look at several content, like wildfly-swarm or Arquillian: I know these projects targets are completely different from mine, but maybe they can be part of the solution? It's just my personal (and possible wrong) thought;

I'm a newbie in the whole "application server" world, so it's highly possible that I'm missing something.

Thanks for any kind reply.

You might want to have a look at WildFly Swarm .

While not documented, there is also the WildFly launcher API . You can see some examples of how it's used in the wildfly-maven-plugn .

Another option would be the application client . Though I'd probably lean towards WildFly Swarm for your use case.

I ended up embedding tomcat 8 within OSGi environment. I really wanted to use the same JVM process for both OSGi and application server (at least to me having 2 separate processes with all the ensuing overhead made no sense), hence embedding tomcat was perfect. Giving up Java EE 7 Full Profile wasn't a big loss since I only needed Web Profile (+ Jersey for web services).

I've written a guide on how to embed tomcat on OSGi here : in case the link will break down, I'll write down here the most important phases:

  1. add to maven all the "tomcat embed" dependencies;
  2. add "felix.service.urlhandlers=false" to config.properties;
  3. Create a new JarScanner from StandardJarScanner where URIs like "http:// .extensions: /" are ignored;
  4. Use context.setJarScanner(JarScanner js) method for every context= tomcat.addWebApp(String, String) call;
  5. Make the "tomcat bundle" a framework extension bundle (see OSGi R6 3.15 section );
  6. Register the "tomcat bundle" service via an "extension bundle activator" via the normal ServiceRegistration procedure;
  7. add the tomcat interface bundle package to "org.osgi.framework.system.packages.extra" config.properties (eg if the interface of "tomcat bundle" is inside com.acme.applicationserver package add "com.acme.applicationserver"

I won't mark this answer as the correct one simply because my question was related to wildfly. I consider this answer only as a workaround (even though for me this answer definitely solve my issue)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM