linux系统如何部署应用程序,如何把java程序部署到linux系统下

2019-01-07 回答

java程序在开发完成后,需要部署到服务器,如果是web项目,需要部署到web服务器,否则部署到应用服务器。

java是跨平台的编程语言,服务器的操作系统可以是windows、linux或者其它,下面将在redhat6操作系统下,详细说明java程序在web服务器和应用服务器上的部署情况。

1、java程序部署在应用服务器

(1) java程序helloworld 在redhat6上部署的目录结构

bin : 存放shell脚本run.sh

conf :存放配置文件log4j.properties

lib :存放jar包helloworld.jar、log4j-1.2.16.jar

logs:存放程序运行日志文件log.log

(2)编写测试类helloworld.java 并打成jar包helloworld.jar

package com.test;

import org.apache.log4j.logger;

import org.apache.log4j.propertyconfigurator;

public class helloworld {

private static logger log = logger.getlogger(helloworld.class);

public static void main(string[] args) {

try{

//log4j.properties变量的值在脚本bin/run.sh 中读取

string config = system.getproperty("log4j.properties");

if (config != null) {

propertyconfigurator.configure(config);

}

log.info("helloworld");

thread thread = new thread(){

public void run(){

while(true){

try {

thread.sleep(5*1000);

log.info("每隔5秒打印一下日志");

} catch (interruptedexception e) {

e.printstacktrace();

log.error(e.getmessage());

}

}

}

};

thread.run();

} catch (exception e) {

log.error("[x]启动失败:"+e.getmessage());

system.exit(1);

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值