Reputation: 309
I do want to run a main class which deploys a jetty server with the content of my vaadin application.
final Server server = new Server();
final Connector connector = new ServerConnector( server );
(( AbstractNetworkConnector ) connector).setPort( 3131 );
server.setConnectors( new Connector[] { connector } ); //
final WebAppContext webappcontext = new WebAppContext();
final File warFile = new File( "target/avx-gcms-1.0.war" );
webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
webappcontext.setContextPath( "/" );
webappcontext.setWar( warFile.getAbsolutePath() );
server.setHandler( webappcontext );
server.start();
System.out.println( "Jetty started, please go to http://localhost:" + 3131 + "/" );
Here is my code for the main method but when I do run this, it works without an error but I do get this in m localhost.
This is my workspace
I have seen some related questions to this yet they were not very helpful. Thank you if you help in advance.
Upvotes: 1
Views: 861
Reputation: 2118
You might want to do it the other way around: instead of war file, make the application as runnable jar directly.
You need to have this main class to the project along with your Vaadin UI class, and wire it up directly to Jetty:
public static void main(String[] args) {
Server server = new Server(3131);
ServletContextHandler contextHandler
= new ServletContextHandler(ServletContextHandler.SESSIONS);
contextHandler.setContextPath("/");
ServletHolder sh = new ServletHolder(new VaadinServlet());
contextHandler.addServlet(sh, "/*");
contextHandler.setInitParameter("ui", HelloWorldUI.class.getCanonicalName());
server.setHandler(contextHandler);
try {
server.start();
server.join();
} catch (Exception ex) {
Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
}
}
Then configure maven-shade-plugin
and exec-maven-plugin
in your pom.xml
to create a runnable jar file like in here.
Check out that project for full example, but note that the setup is bit different with externalised static resources (widgetset and css), but you can skip that configuration in your case.
Upvotes: 1