简体   繁体   English

生产环境中的Javalite框架

[英]Javalite framwork in production env

I am going to ship out the first version of webapp base on Javalite framework. 我将基于Javalite框架发布webapp的第一个版本。 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 我想使用maven-assembly-plugin将所有依赖项组装到一个jar中,命名为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 我想使用以下命令行运行webapp: java -jar myapp-with-dependencies.jar ,以便可以为myapp创建守护程序服务

I've checked all sample apps of Javalite repo on github, Below lists the entry Main.java in development env 我已经在github上检查了Javalite repo的所有示例应用程序,下面列出了开发环境中的Main.java条目

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 ? 如果您有任何在生产环境中运送Javalite的经验,是否可以分享? Thanks! 谢谢!

The example you found is a very simple way to run Jetty embedded. 您发现的示例是运行Jetty Embedded的非常简单的方法。 The other question you asked is about ActiveWeb projects running in a different environment. 您询问的另一个问题是有关在不同环境中运行的ActiveWeb项目的信息。

Please, see http://javalite.io/app-config . 请参阅http://javalite.io/app-config We always use AppConfig to load properties from property files that correspond to a current environment. 我们始终使用AppConfig从对应于当前环境的属性文件中加载属性。 That page contains all the information you need to setup your system for different environments 该页面包含为不同环境设置系统所需的所有信息。

Step 1: 第1步:

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

Step 2 第2步

Add properties to your property file, for instance development.properties : 将属性添加到您的属性文件中,例如development.properties

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

Step 3 第三步

Pull properties with a p() method: 使用p()方法提取属性:

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. 在本地运行时,默认情况下它将读取development.properties文件。

If you set an environment variable ACTIVE_ENV=production , then you code will be reading from the production.properties file. 如果您设置环境变量ACTIVE_ENV=production ,那么您的代码将从production.properties文件中读取。

How we run JavaLite apps in production environment. 我们如何在生产环境中运行JavaLite应用程序。

Generally, we develop using a Jetty Maven plugin - there are many examples of that: https://github.com/javalite 通常,我们使用Jetty Maven插件进行开发-有很多示例: 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. 我们的标准Maven构建会创建一个WAR文件,其中会将所有依赖项作为jar文件包含在WEB_INF / lib下-也就是说,我们不会创建具有依赖项的jar。 Once we have that WAR file, we deploy it on a standard production container, like any other Java app (JBoss, Tomcat, etc.). 一旦有了该WAR文件,便将其部署在标准生产容器上,就像其他任何Java应用程序(JBoss,Tomcat等)一样。

Seems like you are asking 2 different things. 好像您要问2种不同的事情。

Do you want a self executing jar with everything you need in it? 您是否需要一个自我执行的jar,其中包含所需的一切? If so, then you would use a ServletContextHandler not a WAR or WebAppContext . 如果是这样,那么您将使用ServletContextHandler而不是WAR或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". 如果您想使用WebAppContext并使其能够自我执行,那么基本上您将拥有所谓的“ WebAppContext ”。

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. 基本原理是,您将拥有多个管理不同层的Maven(或Gradle)项目,这些项目将需要进行这种实时的设置。

See: 看到:

And example project at 还有示例项目

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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