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项目并运行的功能。

相关推荐
子夜四时歌1 小时前
Python详细安装与环境搭建
开发语言·python
Jinkxs1 小时前
SkyWalking - Python 应用追踪:基于 skywalking-python 的埋点
开发语言·python·skywalking
大头博士先生1 小时前
【3月考】二级Python最新真题及满分代码合集(基本操作题部分)
开发语言·python
xcLeigh1 小时前
IoTDB Python原生接口全攻略:从基础读写到高级实战
开发语言·数据库·python·api·iotdb·原生接口·读写数据
User_芊芊君子1 小时前
文科生封神!Python+AI 零门槛变现:3 天造 App,指令即收入(附脉脉 AI 沙龙干货)
开发语言·人工智能·python
是Dream呀1 小时前
2025年中秋月亮只有94.91%圆?Python告诉你真相
开发语言·python·中秋节
星辰徐哥1 小时前
Python开发从入门到精通:异步编程与协程
开发语言·python
AI智能研究院1 小时前
Python系列进阶教程(一)Python 面向对象
开发语言·python
郁大锤1 小时前
Windows 环境下安装 Python 与环境变量配置
开发语言·windows·python
李德没德1 小时前
零基础快速入门Python:从安装到写出第一个程序
开发语言·python·新人首发