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

相关推荐
用户9083246027313 小时前
Spring AI 1.1.2 + Neo4j:用知识图谱增强 RAG 检索(上篇:图谱构建)
java·spring boot
晨星shine1 天前
GC、Dispose、Unmanaged Resource 和 Managed Resource
后端·c#
用户8307196840821 天前
Spring Boot 集成 RabbitMQ :8 个最佳实践,杜绝消息丢失与队列阻塞
spring boot·后端·rabbitmq
Java水解1 天前
Spring Boot 视图层与模板引擎
spring boot·后端
Java水解1 天前
一文搞懂 Spring Boot 默认数据库连接池 HikariCP
spring boot·后端
用户298698530142 天前
.NET 文档自动化:Spire.Doc 设置奇偶页页眉/页脚的最佳实践
后端·c#·.net
用户3667462526742 天前
接口文档汇总 - 2.设备状态管理
c#
洋洋技术笔记2 天前
Spring Boot Web MVC配置详解
spring boot·后端
用户3667462526742 天前
接口文档汇总 - 3.PLC通信管理
c#
初次攀爬者2 天前
Kafka 基础介绍
spring boot·kafka·消息队列