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

相关推荐
双叶83612 分钟前
(C语言)超市管理系统 (正式版)(指针)(数据结构)(清屏操作)(文件读写)
c语言·开发语言·数据结构·c++·windows
为美好的生活献上中指18 分钟前
java每日精进 5.14【参数校验】
java·开发语言·spring boot·tomcat
qq_124987075324 分钟前
原生小程序+springboot+vue+协同过滤算法的音乐推荐系统(源码+论文+讲解+安装+部署+调试)
java·spring boot·后端·小程序·毕业设计·课程设计·协同过滤
后青春期的诗go40 分钟前
基于Rust语言的Rocket框架和Sqlx库开发WebAPI项目记录(一)
开发语言·后端·rust
信徒_2 小时前
SpringBoot 自动装配流程
java·spring boot·后端
景天科技苑2 小时前
【Rust闭包】rust语言闭包函数原理用法汇总与应用实战
开发语言·后端·rust·闭包·闭包函数·rust闭包·rust闭包用法
uyeonashi3 小时前
【Boost搜索引擎】构建Boost站内搜索引擎实践
开发语言·c++·搜索引擎
再睡一夏就好3 小时前
从硬件角度理解“Linux下一切皆文件“,详解用户级缓冲区
linux·服务器·c语言·开发语言·学习笔记
TIF星空4 小时前
【使用 C# 获取 USB 设备信息及进行通信】
开发语言·经验分享·笔记·学习·microsoft·c#
想太多会累i4 小时前
Spring Boot 使用Itext绘制并导出PDF
spring boot·pdf