简体   繁体   中英

Javalite framwork in production env

I am going to ship out the first version of webapp base on Javalite framework. Thanks the framework, it makes the developing rapidly :). Here are some goals in my production env.

  1. I would like to use maven-assembly-plugin to assemble all dependencies into one jar, named like myapp-with-dependencies.jar
  2. I'd like to run the webapp using command line: java -jar myapp-with-dependencies.jar , so that I can create daemon service for myapp

I've checked all sample apps of Javalite repo on github, Below lists the entry Main.java in development env

public class Main {

  public static void main(String[] args) throws Exception {
    Server server = new Server(8080);
    WebAppContext webapp = new WebAppContext("src/main/webapp", "/"); // <- should package as war in production?
    webapp.addAliasCheck(new AllowSymLinkAliasChecker());
    server.setHandler(webapp);
    server.start();
    server.dumpStdErr();
    server.join();
  }
}

new WebAppContext("src/main/webapp", "/"); only works on development mode? and how to change it to production mode?

The question may be related to embedded-jetty. If you have any experiences on shipping Javalite on production env, could you like to share it ? Thanks!

The example you found is a very simple way to run Jetty embedded. The other question you asked is about ActiveWeb projects running in a different environment.

Please, see http://javalite.io/app-config . We always use AppConfig to load properties from property files that correspond to a current environment. That page contains all the information you need to setup your system for different environments

Step 1:

/app_config
        |
        +--global.properties
        |
        +--development.properties
        |
        +--staging.properties
        |
        +--production.properties

Step 2

Add properties to your property file, for instance development.properties :

first.name=John
phrase= And the name is ${first.name}

Step 3

Pull properties with a p() method:

import static org.javalite.app_config.AppConfig.p;
...
System.out.println(p("phrase"));

When you run locally, it will be reading the development.properties file by default.

If you set an environment variable ACTIVE_ENV=production , then you code will be reading from the production.properties file.

How we run JavaLite apps in production environment.

Generally, we develop using a Jetty Maven plugin - there are many examples of that: https://github.com/javalite

Our standard Maven build creates a WAR file that includes all dependencies as jar files under WEB_INF/lib - that is, we do not create a jar with dependencies. Once we have that WAR file, we deploy it on a standard production container, like any other Java app (JBoss, Tomcat, etc.).

Seems like you are asking 2 different things.

Do you want a self executing jar with everything you need in it? If so, then you would use a ServletContextHandler not a WAR or WebAppContext .

See:

And example project at

If you want to use WebAppContext and have it be self executing, then you'll basically have what's known as a "Live War".

The basics are that you will have multiple maven (or gradle) projects that manage the different layers you will need to pull off this kind of live-war setup.

See:

And example project at

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