有两种方式

1、项目引入portal-kernel.jar、项目运行时使用

根据返回boolean值判断类型!

2、自己写java类

package webService.ZFGX.service;

import org.apache.log4j.Logger;

import webService.ZFGX.utils.ServerUtils;

/**
* 判断服务器类型
* @author landa
*
*/
public class PDFWQ {
private static Logger _log = Logger.getLogger(ServerUtils.class);
public static final String GERONIMO_CLASS = "/org/apache/geronimo/system/main/Daemon.class";
public static final String JBOSS_CLASS = "/org/jboss/Main.class";
public static final String JETTY_CLASS = "/org/mortbay/jetty/Server.class";
public static final String JONAS_CLASS = "/org/objectweb/jonas/server/Server.class";
public static final String OC4J_CLASS = "/oracle/jsp/oc4jutil/Oc4jUtil.class";
public static final String ORION_CLASS = "/com/evermind/server/ApplicationServer.class";
public static final String PRAMATI_CLASS = "/com/pramati/Server.class";
public static final String RESIN_CLASS = "/com/caucho/server/resin/Resin.class";
public static final String REXIP_CLASS = "/com/tcc/Main.class";
public static final String SUN7_CLASS = "/com/iplanet/ias/tools/cli/IasAdminMain.class";
public static final String SUN8_CLASS = "/com/sun/enterprise/cli/framework/CLIMain.class";
public static final String TOMCAT_CLASS = "/org/apache/catalina/startup/Bootstrap.class";
public static final String WEBLOGIC_CLASS = "/weblogic/Server.class";
public static final String WEBSPHERE_CLASS = "/com/ibm/websphere/product/VersionInfo.class"; private String _serverId;
private Boolean _geronimo;
private Boolean _jBoss;
private Boolean _jetty;
private Boolean _jonas;
private Boolean _oc4j;
private Boolean _orion;
private Boolean _pramati;
private Boolean _resin;
private Boolean _rexIP;
private Boolean _sun7;
private Boolean _sun8;
private Boolean _tomcat;
private Boolean _webLogic;
private Boolean _webSphere; private PDFWQ() {
} private static PDFWQ _instance = new PDFWQ(); public static String getServerId() {
PDFWQ sd = _instance;
if (sd._serverId == null) {
if (ServerUtils.isGeronimo()) {
sd._serverId = "geronimo";
} else if (ServerUtils.isJBoss()) {
sd._serverId = "jboss";
} else if (ServerUtils.isJOnAS()) {
sd._serverId = "jonas";
} else if (ServerUtils.isOC4J()) {
sd._serverId = "oc4j";
} else if (ServerUtils.isOrion()) {
sd._serverId = "orion";
} else if (ServerUtils.isResin()) {
sd._serverId = "resin";
} else if (ServerUtils.isWebLogic()) {
sd._serverId = "weblogic";
} else if (ServerUtils.isWebSphere()) {
sd._serverId = "websphere";
}
if (ServerUtils.isJetty()) {
if (sd._serverId == null) {
sd._serverId = "jetty";
} else {
sd._serverId += "-jetty";
}
} else if (ServerUtils.isTomcat()) {
if (sd._serverId == null) {
sd._serverId = "tomcat";
} else {
sd._serverId += "-tomcat";
}
}
if (_log.isInfoEnabled()) {
_log.info("Detected server " + sd._serverId);
}
if (sd._serverId == null) {
throw new RuntimeException("Server is not supported");
}
}
return sd._serverId;
} public static boolean isGeronimo() {
PDFWQ sd = _instance;
if (sd._geronimo == null) {
Class c = sd.getClass();
if (c.getResource(GERONIMO_CLASS) != null) {
sd._geronimo = Boolean.TRUE;
} else {
sd._geronimo = Boolean.FALSE;
}
}
return sd._geronimo.booleanValue();
} public static boolean isJBoss() {
PDFWQ sd = _instance;
if (sd._jBoss == null) {
Class c = sd.getClass();
if (c.getResource(JBOSS_CLASS) != null) {
sd._jBoss = Boolean.TRUE;
} else {
sd._jBoss = Boolean.FALSE;
}
}
return sd._jBoss.booleanValue();
} public static boolean isJetty() {
PDFWQ sd = _instance;
if (sd._jetty == null) {
Class c = sd.getClass();
if (c.getResource(JETTY_CLASS) != null) {
sd._jetty = Boolean.TRUE;
} else {
sd._jetty = Boolean.FALSE;
}
}
return sd._jetty.booleanValue();
} public static boolean isJOnAS() {
PDFWQ sd = _instance;
if (sd._jonas == null) {
Class c = sd.getClass();
if (c.getResource(JONAS_CLASS) != null) {
sd._jonas = Boolean.TRUE;
} else {
sd._jonas = Boolean.FALSE;
}
}
return sd._jonas.booleanValue();
} public static boolean isOC4J() {
PDFWQ sd = _instance;
if (sd._oc4j == null) {
Class c = sd.getClass();
if (c.getResource(OC4J_CLASS) != null) {
sd._oc4j = Boolean.TRUE;
} else {
sd._oc4j = Boolean.FALSE;
}
}
return sd._oc4j.booleanValue();
} public static boolean isOrion() {
PDFWQ sd = _instance;
if (sd._orion == null) {
Class c = sd.getClass();
if (c.getResource(ORION_CLASS) != null) {
sd._orion = Boolean.TRUE;
} else {
sd._orion = Boolean.FALSE;
}
}
return sd._orion.booleanValue();
} public static boolean isPramati() {
PDFWQ sd = _instance;
if (sd._pramati == null) {
Class c = sd.getClass();
if (c.getResource(PRAMATI_CLASS) != null) {
sd._pramati = Boolean.TRUE;
} else {
sd._pramati = Boolean.FALSE;
}
}
return sd._pramati.booleanValue();
} public static boolean isResin() {
PDFWQ sd = _instance;
if (sd._resin == null) {
Class c = sd.getClass();
if (c.getResource(RESIN_CLASS) != null) {
sd._resin = Boolean.TRUE;
} else {
sd._resin = Boolean.FALSE;
}
}
return sd._resin.booleanValue();
} public static boolean isRexIP() {
PDFWQ sd = _instance;
if (sd._rexIP == null) {
Class c = sd.getClass();
if (c.getResource(REXIP_CLASS) != null) {
sd._rexIP = Boolean.TRUE;
} else {
sd._rexIP = Boolean.FALSE;
}
}
return sd._rexIP.booleanValue();
} public static boolean isSun() {
if (isSun7() || isSun8()) {
return true;
} else {
return false;
}
} public static boolean isSun7() {
PDFWQ sd = _instance;
if (sd._sun7 == null) {
Class c = sd.getClass();
if (c.getResource(SUN7_CLASS) != null) {
sd._sun7 = Boolean.TRUE;
} else {
sd._sun7 = Boolean.FALSE;
}
}
return sd._sun7.booleanValue();
} public static boolean isSun8() {
PDFWQ sd = _instance;
if (sd._sun8 == null) {
Class c = sd.getClass();
if (c.getResource(SUN8_CLASS) != null) {
sd._sun8 = Boolean.TRUE;
} else {
sd._sun8 = Boolean.FALSE;
}
}
return sd._sun8.booleanValue();
} public static boolean isTomcat() {
PDFWQ sd = _instance;
if (sd._tomcat == null) {
Class c = sd.getClass();
if (c.getResource(TOMCAT_CLASS) != null) {
sd._tomcat = Boolean.TRUE;
} else {
sd._tomcat = Boolean.FALSE;
}
}
return sd._tomcat.booleanValue();
} public static boolean isWebLogic() {
PDFWQ sd = _instance;
if (sd._webLogic == null) {
Class c = sd.getClass();
if (c.getResource(WEBLOGIC_CLASS) != null) {
sd._webLogic = Boolean.TRUE;
} else {
sd._webLogic = Boolean.FALSE;
}
}
return sd._webLogic.booleanValue();
} public static boolean isWebSphere() {
PDFWQ sd = _instance;
if (sd._webSphere == null) {
Class c = sd.getClass();
if (c.getResource(WEBSPHERE_CLASS) != null) {
sd._webSphere = Boolean.TRUE;
} else {
sd._webSphere = Boolean.FALSE;
}
}
return sd._webSphere.booleanValue();
} }

然后判断方式与方法一一致!

java判断部署项目使用的服务器类型的更多相关文章

  1. IntelliJ IDEA自动部署项目至远程服务器与传统部署项目至远程服务器的区别

    每次开发Java项目时,对于所有Java开发人员来说,最枯燥的不是修改代码,而是实时将自己的代码上传至远程服务器,进行测试或者部署,本人最初开发也是这样,通过使用Xshell 5,WinSCP等工具对 ...

  2. Vue-CLI 3.x 部署项目至生产服务器

    本文已同步到专业技术网站 www.sufaith.com, 该网站专注于前后端开发技术与经验分享, 包含Web开发.Nodejs.Python.Linux.IT资讯等板块. 本教程主要讲解的是 Vue ...

  3. myeclipse 无法部署项目到jboss服务器 部署不上去

    关于myeclipse部署项目到jboss点击add deployments没有反应的问题,如图 此处点击右键,选择add deployments没有反应,原因是默认的web-root folder为 ...

  4. AWS云部署项目——数据库与服务器

    1.连接数据库 选择服务RDS,进入后点击数据库实例,在之前建好的数据库内进行操作 首先是安全组,类似于aws云上的防火墙一样的东西,先设置好公开性,安全组置为default(就是尽量避免测试时访问阻 ...

  5. 通过GitHub部署项目到Nginx服务器

    1.更新源: 2.安装nginx 3.安装成功 4.DNS域名解析 5.访问域名就会找到相应IP地址的主机,一个IP可对应多个域名 6.提交到gitHub 复制这两行 填上邮箱和密码 7.提交成功 8 ...

  6. 使用IDEA部署项目到远程服务器

    1.选择Tools -> Deployment -> Configuration... 2.配置连接信息,Linux服务器一般都选择SFTP 3.配置本地上传文件路径.远程上传文件路径 4 ...

  7. IDEA部署项目到远程服务器

    一.idea安装阿里插件Alibaba Cloud Toolkit 二.添加Host 三.应用部署 四.修改源程序重新部署 五.查看实时日志 欲买桂花同载酒,终不似,少年游

  8. Webstorm轻松部署项目至服务器

    wo大前端在开发环境下,需要将项目部署到测试环境,webstorm进行基础配置操作就可实现. 一.在Deployment选项下配置远程服务器地址 点击加号,选择type类型,Name自己填,帮你找到这 ...

  9. 最新JetBrainsPyCharm自动部署Python(Django,tornado等)项目至远程服务器

    每次开发Python项目时,对于所有Python开发人员来说,最枯燥的不是修改代码,而是实时将自己的代码上传至远程服务器,进行测试或者部署,本人最初开发也是这样,通过使用Xshell 5,WinSCP ...

随机推荐

  1. maven测试时中文乱码问题解决方法

    pom.xml增加-Dfile.encoding=UTF-8配置,如下: <plugin> <!--升级到新版本解决控制台乱码问题--> <groupId>org. ...

  2. "去QE化"的思考

    最近测试圈子里流传一篇有关去QE(Quality Engineer)的文章,此文如平地惊雷,突然在圈子里炸开了锅.文中所述使很多同行有点人人自危,担心行业未来和自身发展前程,而后不久就有大神写出“去Q ...

  3. 编译nginx平滑添加stream模块

    1.操作背景 操作系统版本:CentOS Linux release (Core) nginx版本:1.13.4 nginx从1.9.0版本开始,新增了ngx_stream_core_module模块 ...

  4. hdwiki 部署

    1.安装wamp 集成环境(部署过程出现的环境问题请搜索我的另外一篇文章 <wamp安装失败原因大全>)2.到 http://kaiyuan.hudong.com/download/ 下载 ...

  5. bzoj1047&bzoj1012

    Description 有一个a*b的整数组成的矩阵,现请你从中找出一个n*n的正方形区域,使得该区域所有数中的最大值和最小值的差最小. Input 第一行为3个整数,分别表示a,b,n的值第二行至第 ...

  6. AtCoder Grand Contest 006

    AtCoder Grand Contest 006 吐槽 这套题要改个名字,叫神仙结论题大赛 A - Prefix and Suffix 翻译 给定两个串,求满足前缀是\(S\),后缀是\(T\),并 ...

  7. Vitrualbox 桥接网卡界面名称未指定、Filters currently installed on the system have reached the limit、不能为虚拟电脑 打开一个新任务

    1. 桥接网卡界面名称未指定 http://wenku.baidu.com/link?url=VFG0hknsDX3VPXQoX5f-g1wUX_LBl-lOj0ZqD222kM31iVCPJKVu3 ...

  8. 【bzoj2878】 Noi2012—迷失游乐园

    http://www.lydsy.com/JudgeOnline/problem.php?id=2878 (题目链接) 题意 求基环树上以任意点为起点的简单路径期望长度. Solution 啊啊啊好丑 ...

  9. 伤不起:File.toPath() & Paths.get()

    java.nio.file.Path这个类应该是从java7才开始有的. 通过File类有两个方法可以转换成Path. 1. Path p = Paths.get(file.toURI());  // ...

  10. Controller、Service、Dao进行Junit单元

    原文链接:http://blog.csdn.net/u013041642/article/details/71430293 Spring对Controller.Service.Dao进行Junit单元 ...