clasapath 和 jar 兼容,静态资源添加回话url参数

This commit is contained in:
jiangzeyin 2019-03-29 14:08:39 +08:00
parent acb0999445
commit 4c7f85d930
12 changed files with 180 additions and 99 deletions

View File

@ -177,7 +177,7 @@ public abstract class AbstractCommander {
} }
private VirtualMachine getVirtualMachine(String tag) throws IOException, AttachNotSupportedException { private VirtualMachine getVirtualMachine(String tag) throws IOException, AttachNotSupportedException {
tag = String.format("-Dapplication=%s", tag); tag = String.format("-Dapplication=%s ", tag);
// 通过VirtualMachine.list()列出所有的java进程 // 通过VirtualMachine.list()列出所有的java进程
List<VirtualMachineDescriptor> descriptorList = VirtualMachine.list(); List<VirtualMachineDescriptor> descriptorList = VirtualMachine.list();
for (VirtualMachineDescriptor virtualMachineDescriptor : descriptorList) { for (VirtualMachineDescriptor virtualMachineDescriptor : descriptorList) {
@ -185,6 +185,9 @@ public abstract class AbstractCommander {
VirtualMachine virtualMachine = VirtualMachine.attach(virtualMachineDescriptor); VirtualMachine virtualMachine = VirtualMachine.attach(virtualMachineDescriptor);
Properties properties = virtualMachine.getAgentProperties(); Properties properties = virtualMachine.getAgentProperties();
String args = properties.getProperty("sun.jvm.args", ""); String args = properties.getProperty("sun.jvm.args", "");
if (StrUtil.isEmpty(args)) {
args = properties.getProperty("sun.java.command", "");
}
if (StrUtil.containsIgnoreCase(args, tag)) { if (StrUtil.containsIgnoreCase(args, tag)) {
return virtualMachine; return virtualMachine;
} }

View File

@ -25,7 +25,7 @@ public class LinuxCommander extends AbstractCommander {
return msg; return msg;
} }
// 拼接命令 // 拼接命令
String command = String.format("nohup java %s -classpath %s -Dapplication=%s -Dbasedir=%s %s %s >> %s 2>&1 &", String command = String.format("nohup java %s %s -Dapplication=%s -Dbasedir=%s %s %s >> %s 2>&1 &",
projectInfoModel.getJvm(), projectInfoModel.getJvm(),
ProjectInfoModel.getClassPathLib(projectInfoModel), ProjectInfoModel.getClassPathLib(projectInfoModel),
projectInfoModel.getId(), projectInfoModel.getId(),

View File

@ -31,7 +31,7 @@ public class WindowsCommander extends AbstractCommander {
String args = projectInfoModel.getArgs(); String args = projectInfoModel.getArgs();
String classPath = ProjectInfoModel.getClassPathLib(projectInfoModel); String classPath = ProjectInfoModel.getClassPathLib(projectInfoModel);
String command = String.format("javaw %s -classpath %s -Dapplication=%s -Dbasedir=%s %s %s >> %s &", String command = String.format("javaw %s %s -Dapplication=%s -Dbasedir=%s %s %s >> %s &",
jvm, classPath, tag, jvm, classPath, tag,
projectInfoModel.getAbsoluteLib(), mainClass, args, projectInfoModel.getAbsoluteLog()); projectInfoModel.getAbsoluteLib(), mainClass, args, projectInfoModel.getAbsoluteLog());
// 执行命令; // 执行命令;

View File

@ -1,10 +1,12 @@
package cn.keepbx.jpom.common.interceptor; package cn.keepbx.jpom.common.interceptor;
import cn.hutool.core.date.DateUtil;
import cn.jiangzeyin.common.interceptor.BaseInterceptor; import cn.jiangzeyin.common.interceptor.BaseInterceptor;
import cn.jiangzeyin.common.interceptor.InterceptorPattens; import cn.jiangzeyin.common.interceptor.InterceptorPattens;
import cn.keepbx.jpom.common.BaseController; import cn.keepbx.jpom.common.BaseController;
import cn.keepbx.jpom.model.UserModel; import cn.keepbx.jpom.model.UserModel;
import org.springframework.web.method.HandlerMethod; import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -42,6 +44,16 @@ public class LoginInterceptor extends BaseInterceptor {
return true; return true;
} }
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
super.postHandle(request, response, handler, modelAndView);
HttpSession session = getSession();
Object staticCacheTime = session.getAttribute("staticCacheTime");
if (staticCacheTime == null) {
session.setAttribute("staticCacheTime", DateUtil.currentSeconds());
}
}
@Override @Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
super.afterCompletion(request, response, handler, ex); super.afterCompletion(request, response, handler, ex);

View File

@ -69,6 +69,9 @@ public class EditProjectController extends BaseController {
} }
} }
setAttribute("item", projectInfo); setAttribute("item", projectInfo);
// 运行模式
ProjectInfoModel.RunMode[] runModes = ProjectInfoModel.RunMode.values();
setAttribute("runModes", runModes);
return "manage/editProject"; return "manage/editProject";
} }
@ -92,6 +95,16 @@ public class EditProjectController extends BaseController {
if (LogWebSocketHandle.SYSTEM_ID.equals(id)) { if (LogWebSocketHandle.SYSTEM_ID.equals(id)) {
return JsonMessage.getString(401, "项目id " + LogWebSocketHandle.SYSTEM_ID + " 关键词被系统占用"); return JsonMessage.getString(401, "项目id " + LogWebSocketHandle.SYSTEM_ID + " 关键词被系统占用");
} }
//
String runMode = getParameter("runMode");
ProjectInfoModel.RunMode runMode1 = ProjectInfoModel.RunMode.ClassPath;
try {
runMode1 = ProjectInfoModel.RunMode.valueOf(runMode);
} catch (Exception ignored) {
}
projectInfo.setRunMode(runMode1);
System.out.println(runMode1);
// //
if (!whitelistDirectoryService.checkProjectDirectory(whitelistDirectory)) { if (!whitelistDirectoryService.checkProjectDirectory(whitelistDirectory)) {
return JsonMessage.getString(401, "请选择正确的项目路径,或者还没有配置白名单"); return JsonMessage.getString(401, "请选择正确的项目路径,或者还没有配置白名单");
@ -179,6 +192,7 @@ public class EditProjectController extends BaseController {
exits.setJvm(projectInfo.getJvm()); exits.setJvm(projectInfo.getJvm());
exits.setArgs(projectInfo.getArgs()); exits.setArgs(projectInfo.getArgs());
exits.setBuildTag(projectInfo.getBuildTag()); exits.setBuildTag(projectInfo.getBuildTag());
exits.setRunMode(projectInfo.getRunMode());
// //
moveTo(exits, projectInfo); moveTo(exits, projectInfo);
projectInfoService.updateProject(exits); projectInfoService.updateProject(exits);
@ -261,7 +275,7 @@ public class EditProjectController extends BaseController {
} }
private JsonMessage checkPath(ProjectInfoModel projectInfoModel) throws IOException { private JsonMessage checkPath(ProjectInfoModel projectInfoModel) {
List<ProjectInfoModel> projectInfoModelList = projectInfoService.list(); List<ProjectInfoModel> projectInfoModelList = projectInfoService.list();
for (ProjectInfoModel model : projectInfoModelList) { for (ProjectInfoModel model : projectInfoModelList) {
if (!model.getId().equals(projectInfoModel.getId())) { if (!model.getId().equals(projectInfoModel.getId())) {

View File

@ -48,6 +48,19 @@ public class ProjectInfoModel extends BaseModel {
*/ */
private String modifyUser; private String modifyUser;
private RunMode runMode;
public RunMode getRunMode() {
if (runMode == null) {
return RunMode.ClassPath;
}
return runMode;
}
public void setRunMode(RunMode runMode) {
this.runMode = runMode;
}
public String getModifyUser() { public String getModifyUser() {
if (StrUtil.isEmpty(modifyUser)) { if (StrUtil.isEmpty(modifyUser)) {
return UserModel.SYSTEM_OCCUPY_NAME; return UserModel.SYSTEM_OCCUPY_NAME;
@ -161,14 +174,26 @@ public class ProjectInfoModel extends BaseModel {
public static String getClassPathLib(ProjectInfoModel projectInfoModel) { public static String getClassPathLib(ProjectInfoModel projectInfoModel) {
File fileLib = new File(projectInfoModel.getLib()); File fileLib = new File(projectInfoModel.getLib());
File[] files = fileLib.listFiles(); File[] files = fileLib.listFiles();
if (files == null) { if (files == null || files.length <= 0) {
return ""; return "";
} }
int len = files.length;
// 获取lib下面的所有jar包 // 获取lib下面的所有jar包
StringBuilder classPath = new StringBuilder(); StringBuilder classPath = new StringBuilder();
RunMode runMode = projectInfoModel.getRunMode();
for (File file : files) { if (runMode == RunMode.ClassPath) {
classPath.append(file.getAbsolutePath()).append(AbstractCommander.OS_INFO.isWindows() ? ";" : ":"); classPath.append("-classpath ");
} else if (runMode == RunMode.Jar) {
classPath.append("-jar ");
// 只取一个jar
len = 1;
}
for (int i = 0; i < len; i++) {
File file = files[i];
classPath.append(file.getAbsolutePath());
if (i != len - 1) {
classPath.append(AbstractCommander.OS_INFO.isWindows() ? ";" : ":");
}
} }
return classPath.toString(); return classPath.toString();
} }
@ -234,4 +259,18 @@ public class ProjectInfoModel extends BaseModel {
public JSONObject toJson() { public JSONObject toJson() {
return (JSONObject) JSONObject.toJSON(this); return (JSONObject) JSONObject.toJSON(this);
} }
/**
* 运行方式
*/
public enum RunMode {
/**
* java -classpath
*/
ClassPath,
/**
* java -jar
*/
Jar,
}
} }

View File

@ -1,80 +0,0 @@
/* 选项卡 */
.layui-tab {
margin: 0;
height: 100%;
}
.layui-body {
bottom: 10px !important;
}
.layui-tab-title {
/*width: calc(100% - 100px)*/
right: 70px;
}
.layui-tab-content {
position: absolute;
padding: 0px;
top: 40px;
right: 0;
bottom: 0;
left: 0;
}
.layui-tab-item {
height: 100%;
width: 100%;
}
/* <20><>Ƕ<EFBFBD><C7B6><EFBFBD><EFBFBD><EFBFBD>ʽ*/
.custom-iframe {
width: 100%;
height: 100%;
}
.layui-tab-title li:first-child > i {
display: none;
}
.custom-nav {
position: absolute;
padding: 0px;
top: 0;
right: 0;
height: 42px;
background-color: #fff !important;
color: #000;
border-bottom: 1px solid #e2e2e2;
border-left: 1px solid #e2e2e2;
}
.custom-nav .layui-nav-item {
line-height: 41px;
background-color: #f2f2f2;
}
.custom-nav .layui-nav-item a {
color: #000;
}
.custom-nav .layui-nav-item a:hover {
color: #000;
}
.custom-nav .layui-nav-item .layui-nav-more {
top: 18px;
border-top-color: rgba(0, 0, 0, 0.7);
border-bottom-color: rgba(0, 0, 0, 0);
}
.custom-nav .layui-nav-item .layui-nav-mored {
top: 12px;
border-top-color: rgba(0, 0, 0, 0);
border-bottom-color: rgba(0, 0, 0, 1);
}
#div-updatePwd {
padding: 15px;
display: none;
}

View File

@ -5,8 +5,8 @@
<meta name="apple-mobile-web-app-status-bar-style" content="black"> <meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="icon" href="/static/favicon.ico" type="image/x-icon"/> <link rel="icon" href="/static/favicon.ico" type="image/x-icon"/>
<link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon"/> <link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon"/>
<link rel="stylesheet" href="/static/layui/css/layui.css" media="all"> <link rel="stylesheet" href="/static/layui/css/layui.css?v=$staticCacheTime" media="all">
<script type="text/javascript" src="/static/layui/layui.js"></script> <script type="text/javascript" src="/static/layui/layui.js?v=$staticCacheTime"></script>
<script type="text/javascript"> <script type="text/javascript">
var $, layer, form, element, table; var $, layer, form, element, table;
layui.use(['layer', 'element', 'form', 'table'], function () { layui.use(['layer', 'element', 'form', 'table'], function () {

View File

@ -4,7 +4,88 @@
<head> <head>
<title>Jpom-项目管理系统</title> <title>Jpom-项目管理系统</title>
#parse("./common/head.vm") #parse("./common/head.vm")
<link rel="stylesheet" href="/static/css/index.css"> <style>
/* 选项卡 */
.layui-tab {
margin: 0;
height: 100%;
}
.layui-body {
bottom: 10px !important;
}
.layui-tab-title {
/*width: calc(100% - 100px)*/
right: 70px;
}
.layui-tab-content {
position: absolute;
padding: 0px;
top: 40px;
right: 0;
bottom: 0;
left: 0;
}
.layui-tab-item {
height: 100%;
width: 100%;
}
/* <20><>Ƕ<EFBFBD><C7B6><EFBFBD><EFBFBD><EFBFBD>ʽ*/
.custom-iframe {
width: 100%;
height: 100%;
}
.layui-tab-title li:first-child > i {
display: none;
}
.custom-nav {
position: absolute;
padding: 0px;
top: 0;
right: 0;
height: 42px;
background-color: #fff !important;
color: #000;
border-bottom: 1px solid #e2e2e2;
border-left: 1px solid #e2e2e2;
}
.custom-nav .layui-nav-item {
line-height: 41px;
background-color: #f2f2f2;
}
.custom-nav .layui-nav-item a {
color: #000;
}
.custom-nav .layui-nav-item a:hover {
color: #000;
}
.custom-nav .layui-nav-item .layui-nav-more {
top: 18px;
border-top-color: rgba(0, 0, 0, 0.7);
border-bottom-color: rgba(0, 0, 0, 0);
}
.custom-nav .layui-nav-item .layui-nav-mored {
top: 12px;
border-top-color: rgba(0, 0, 0, 0);
border-bottom-color: rgba(0, 0, 0, 1);
}
#div-updatePwd {
padding: 15px;
display: none;
}
</style>
</head> </head>
<body class="layui-layout-body"> <body class="layui-layout-body">
@ -51,10 +132,10 @@
<a href="javascript:;" <a href="javascript:;"
data-options="{'id':'alioss', 'title':'阿里云OSS', 'url':'/system/alioss'}">阿里云OSS</a> data-options="{'id':'alioss', 'title':'阿里云OSS', 'url':'/system/alioss'}">阿里云OSS</a>
</li> </li>
## <li class="layui-nav-item"> ## <li class="layui-nav-item">
## <a href="javascript:;" ## <a href="javascript:;"
## data-options="{'id':'certificate', 'title':'证书管理', 'url':'/system/certificate'}">证书管理</a> ## data-options="{'id':'certificate', 'title':'证书管理', 'url':'/system/certificate'}">证书管理</a>
## </li> ## </li>
<li class="layui-nav-item"> <li class="layui-nav-item">
<a href="javascript:;" <a href="javascript:;"
data-options="{'id':'nginx', 'title':'nginx管理', 'url':'/system/nginx'}">nginx管理</a> data-options="{'id':'nginx', 'title':'nginx管理', 'url':'/system/nginx'}">nginx管理</a>

View File

@ -9,7 +9,7 @@
<body> <body>
<div class="layui-carousel" id="div-carousel" style="width: 100%; height: 100%; position: fixed; z-index: 0;"> <div class="layui-carousel" id="div-carousel" style="width: 100%; height: 100%; position: fixed; z-index: 0;">
<div carousel-item> <div carousel-item>
<div><img src="/static/backgrounds/1.jpg" style="width: 100%;"></div> <div><img src="/static/backgrounds/1.jpg?v=$staticCacheTime" style="width: 100%;"></div>
</div> </div>
</div> </div>
<div class="layui-container" style="margin-top: 150px;"> <div class="layui-container" style="margin-top: 150px;">

View File

@ -21,9 +21,9 @@
<body> <body>
<div class="layui-carousel auto" id="div-carousel" style=" position: fixed; z-index: 0;"> <div class="layui-carousel auto" id="div-carousel" style=" position: fixed; z-index: 0;">
<div carousel-item> <div carousel-item>
<div><img src="/static/backgrounds/1.jpg" class="auto"></div> <div><img src="/static/backgrounds/1.jpg?v=$staticCacheTime" class="auto"></div>
<div><img src="/static/backgrounds/2.jpg" class="auto"></div> <div><img src="/static/backgrounds/2.jpg?v=$staticCacheTime" class="auto"></div>
<div><img src="/static/backgrounds/3.jpg" class="auto"></div> <div><img src="/static/backgrounds/3.jpg?v=$staticCacheTime" class="auto"></div>
</div> </div>
</div> </div>
<div class="layui-container" style="margin-top: 150px;"> <div class="layui-container" style="margin-top: 150px;">

View File

@ -95,6 +95,18 @@
</div> </div>
</div> </div>
</div> </div>
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">运行方式</label>
<div class="layui-input-block">
<select name="runMode">
#foreach($itemPath in $runModes)
<option value="$itemPath" #if($item.runMode==$itemPath)selected#end>$itemPath</option>
#end
</select>
</div>
</div>
</div>
<div class="layui-form-item"> <div class="layui-form-item">
<div class="layui-inline"> <div class="layui-inline">
<label class="layui-form-label">Jvm参数</label> <label class="layui-form-label">Jvm参数</label>