c#运行spring boot项目

Idea提供了一个很方便地运行spring boot项目的环境,我想要自己实现一个。因为用java -jar 命令可以运行java程序,所以我设想用C#调用cmd.exe来执行shell命令。这个设想来自于在linux上运行java程序的经验。

程序窗体:

"打开"按钮处理方法

csharp 复制代码
 private void button2_Click(object sender, EventArgs e)
 {
     var myFileDialog=new FolderBrowserDialog();
     if (myFileDialog.ShowDialog() ==DialogResult.OK)
     {
         var myPath=myFileDialog.SelectedPath;
         //MessageBox.Show(myPath);
         this.myFilePath = myPath;
     }
 }

打开一个目录选择对话框,您可以选择spring boot项目根目录。

"启动"按钮处理方法

csharp 复制代码
 private void button1_Click(object sender, EventArgs e)
 {
     this.myFilePath = "D:/迅雷下载/seleniumhq.github.io-trunk/java3/demo3";
     char[] separator=new char[] { '/' };
     string[] strArr = this.myFilePath.Split(separator);
     //MessageBox.Show(strArr[strArr.Length - 1]);
     string strCmdText;
     string anyCommand = this.myFilePath.ToCharArray()[0].ToString() + ": & cd "+this.myFilePath+" & mvn clean & mvn package -DskipTests=true & cd target & java -jar "+ strArr[strArr.Length - 1] + "-0.0.1-SNAPSHOT.jar";
     strCmdText = "/C " + anyCommand;
     
     Process.Start("CMD.exe", strCmdText);

 }

strCmdText = "/C " + anyCommand中的anyCommand代表任意shell命令,那我们就能模拟出linux终端了。

该程序实现了定位spring boot项目并运行的功能。

相关推荐
ch.ju11 分钟前
Java Programming Chapter 3——Default value of array
java·开发语言
aini_lovee15 分钟前
STM32 上实现 SD 卡读取 JPEG 解码 TFT 显示
开发语言·stm32
谙弆悕博士17 分钟前
【附C语言源码】C语言 栈结构 实现及其扩展操作
c语言·开发语言·数据结构·算法·链表·指针·
njsgcs18 分钟前
c# solidworks GetPartBox无法获得正确实体边界框原因
开发语言·c#·solidworks
bandaoyu18 分钟前
【CUDA】store/load普通访存 vs 非临时(Non-Temporal)访存
java·开发语言·redis
逍遥德19 分钟前
常见的任务调度框架介绍
java·spring boot·中间件
天天进步201526 分钟前
透视 Mission Control 源码:如何构建高性能的 Agent 实时监控架构?
开发语言
apple爱加油26 分钟前
线程相关_线程池原理
开发语言·python
小短腿的代码世界28 分钟前
Qt_Qwt深度解析:从源码到工业级性能优化
开发语言·qt·性能优化
charlie11451419130 分钟前
基于开源项目的现代C++实战——OnceCallback 实战(五):then 链式组合
开发语言·c++·开源