有两种方式

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. aop 例外通知就是记录业务方法出现错误 并保存到日志里面的功能

    aop 例外通知就是记录业务方法出现错误 并保存到日志里面的功能

  2. Luogu4980 【模板】Polya定理(Polya定理+欧拉函数)

    对于置换0→i,1→i+1……,其中包含0的循环的元素个数显然是n/gcd(i,n),由对称性,循环节个数即为gcd(i,n). 那么要求的即为Σngcd(i,n)/n(i=0~n-1,也即1~n). ...

  3. 2017-2018 ACM-ICPC, Asia Daejeon Regional Contest C(记忆化搜索)

    C题 Problem C Game Map 思路: 之前暴力搜索写了好几发,一直超时,后面看其他人的题解发现要用记忆化搜索..直接暴力搜的话有太多重 复的计算. dist u 表示以u 为起点所能走的 ...

  4. 【bzoj1089】严格n元树

    Description 如果一棵树的所有非叶节点都恰好有n个儿子,那么我们称它为严格n元树.如果该树中最底层的节点深度为d(根的深度为0),那么我们称它为一棵深度为d的严格n元树.例如,深度为2的严格 ...

  5. 【BZOJ4477】[JSOI2015]字符串树(Trie树)

    [BZOJ4477][JSOI2015]字符串树(Trie树) 题面 BZOJ 题解 对于每个点维护其到根节点的所有字符串构成的\(Trie\),显然可持久化一下就很好写了. 然后每次询问就是\(u+ ...

  6. codeforces906 D

    题目链接:http://codeforces.com/contest/906/problem/D 题意: 给你n个数,再给你l~r,求%m 题解: 一开始不会 后来查到了欧拉降幂定理: 然后就会了 这 ...

  7. 【字符串算法2】浅谈Manacher算法

    [字符串算法1] 字符串Hash(优雅的暴力) [字符串算法2]Manacher算法 [字符串算法3]KMP算法 这里将讲述  字符串算法2:Manacher算法 问题:给出字符串S(限制见后)求出最 ...

  8. 【bzoj3994】 SDOI2015—约数个数和

    http://www.lydsy.com/JudgeOnline/problem.php?id=3994 (题目链接) 题意 多组询问,给出${n,m}$,求${\sum_{i=1}^n\sum_{j ...

  9. HDU 6158 笛卡尔定理+韦达定理

    The Designer Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  10. 使用Python的turtle(海龟)模块画图

    第一步:让Python引入turtle模块,引入模块就是告诉Python你想要用它. import turtle 第二步:创建画布.调用turtle中的Pen函数 t = turtle.Pen() 第 ...