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.
maven-assembly-plugin
to assemble all dependencies into one jar, named like myapp-with-dependencies.jar
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.).