At this moment, Azure Service Fabric does not support JAVA application natively (but it's on the support roadmap). However, we can host the JAVA application as a Guest Executable for the time being.
In this article, I will walk you through how to deploy JAVA application on Azure Service Fabric in details.
-
Prepare JAVA Application
I follow the Embedded Jetty Examples to create a simple file server.
The source code is like below.View Code1 package org.eclipse.jetty.embedded; 2 3 import org.eclipse.jetty.server.Handler; 4 import org.eclipse.jetty.server.Server; 5 import org.eclipse.jetty.server.handler.DefaultHandler; 6 import org.eclipse.jetty.server.handler.HandlerList; 7 import org.eclipse.jetty.server.handler.ResourceHandler; 8 9 public class FileServer { 10 11 public static void main(String[] args) throws Exception{ 12 // TODO Auto-generated method stub 13 // Create a basic Jetty server object that will listen on port 8080. Note that if you set this to port 0 14 // then a randomly available port will be assigned that you can either look in the logs for the port, 15 // or programmatically obtain it for use in test cases. 16 Server server = new Server(8080); 17 18 // Create the ResourceHandler. It is the object that will actually handle the request for a given file. It is 19 // a Jetty Handler object so it is suitable for chaining with other handlers as you will see in other examples. 20 ResourceHandler resource_handler = new ResourceHandler(); 21 22 // Configure the ResourceHandler. Setting the resource base indicates where the files should be served out of. 23 // In this example it is the current directory but it can be configured to anything that the jvm has access to. 24 resource_handler.setDirectoriesListed(true); 25 resource_handler.setWelcomeFiles(new String[]{ "index.html" }); 26 resource_handler.setResourceBase("."); 27 28 // Add the ResourceHandler to the server. 29 HandlerList handlers = new HandlerList(); 30 handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() }); 31 server.setHandler(handlers); 32 33 // Start things up! By using the server.join() the server thread will join with the current thread. 34 // See "http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html#join()" for more details. 35 server.start(); 36 server.join(); 37 } 38 39 }