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

相关推荐
码银10 分钟前
【数据结构】顺序表
java·开发语言·数据结构
一个儒雅随和的男子21 分钟前
多级缓存解决方案
spring boot·缓存
橘子海全栈攻城狮26 分钟前
【源码+文档+调试讲解】基于Spring Boot的考务管理系统设计与实现 085
java·spring boot·后端·spring
William_cl1 小时前
C# ASP.NET MVC 数据验证实战:View 层双保险(Html.ValidationMessageFor + jQuery Validate)
后端·c#·asp.net·mvc
Python私教1 小时前
Python 开发环境安装与配置全指南(2025版)
开发语言·python
百锦再1 小时前
第12章 测试编写
android·java·开发语言·python·rust·go·erlang
无敌最俊朗@1 小时前
C++ 并发与同步速查笔记(整理版)
开发语言·c++·算法
Elastic 中国社区官方博客1 小时前
Observability:适用于 PHP 的 OpenTelemetry:EDOT PHP 加入 OpenTelemetry 项目
大数据·开发语言·人工智能·elasticsearch·搜索引擎·全文检索·php
csbysj20202 小时前
PHP 魔术常量
开发语言