用jsp调用exe文件

以下内容当时是看过好几个参考资料才整理出来,但是当时没写记录,师妹问到,才给她写教程,所以不记得看谁的了,声明不是本人自己研究出来,但做了整理!

 

1、把myeclipse工程export 成jar文件

 如果该工程调用了其他的jar文件那么要新建一个MANIFEST.MF 文件, 内容如下(Manifest-Version: 1.0中间有个空格,下面也是一样,class-Path:后面是引用的jar包,放在libs目录下)

Manifest-Version: 1.0
Class-Path: libs/javacpp.jar libs/javacv.jar libs/mysql-connector-java-5.1.7-bin.jar libs/opencv.jar libs/opencv-249.jar libs/opencv-windows-x86_64.jar
Main-Class: MainInfo

文件->export -> jar file -> 选择工程文件和Manifest-Version 以及用到的其他的图片之类的文件,finish。

 

2、jar 文件转成exe文件,其实有工具可以转,但是总是会出现一个黑框框,所以干脆用vs c#转

下面是c#代码,需要改两个地方;

1) string cmd =“”; 后面jar包就是第一步生成的jar包

2)

[html]  view plain  copy
 
  在CODE上查看代码片 派生到我的代码片
  1. p.StartInfo.WorkingDirectory = "C:\\Program Files\\MarkVideo\\"; 这个是jar执行时候放在的目录。  

 

 

[html]  view plain  copy
 
  在CODE上查看代码片 派生到我的代码片
  1. using System;  
  2. using System.Diagnostics;  
  3. using System.Text.RegularExpressions;  
  4. using System.Windows.Forms;  
  5.   
  6. namespace MarkVideoTool  
  7. {  
  8.     static class Program  
  9.     {  
  10.         /// <summary>  
  11.         /// 应用程序的主入口点。  
  12.         /// </summary>  
  13.         [STAThread]  
  14.         static void Main(string[] args)  
  15.         {  
  16.               
  17.             string cmd = "start javaw -jar MarkVideoTool.jar";  
  18.             RunCmd(cmd);  
  19.         }  
  20.   
  21.         private static void RunCmd(string command)  
  22.         {  
  23.             Process p = new Process();  
  24.             p.StartInfo.WorkingDirectory = "C:\\Program Files\\MarkVideo\\";  
  25.             p.StartInfo.FileName = "cmd.exe";  
  26.             p.StartInfo.Arguments = "/c "+command;  
  27.             p.StartInfo.UseShellExecute = false;  
  28.             p.StartInfo.RedirectStandardInput = true;  
  29.             p.StartInfo.RedirectStandardOutput = true;  
  30.             p.StartInfo.RedirectStandardError = true;  
  31.             p.StartInfo.CreateNoWindow = true;  
  32.             p.Start();  
  33.           //  p.StandardInput.WriteLine(command);  
  34.           //  p.StandardInput.WriteLine("exit");  
  35.           //  p.StandardOutput.ReadToEnd();  
  36.             p.Close();  
  37.         }  
  38.     }  
  39. }  

3、把上面的jar、exe等其他关联文件放在 workingDirectory目录下。

 

4、新建一个reg文件。for example(MarkVideo.reg)  内容如下

URL 就是生成的exe放的地址,把下面三个地址、项目名字换掉,双击注册

 

[html]  view plain  copy
 
  在CODE上查看代码片 派生到我的代码片
  1. Windows Registry Editor Version 5.00  
  2. [HKEY_CLASSES_ROOT\<span style="color:#ff0000;">MarkVideo</span>]  
  3. "URL Protocol"="C:\\Program Files\\MarkVideo\\MarkVideoTool.exe"  
  4. @="MarkVideoProtocol"  
  5. [HKEY_CLASSES_ROOT\MarkVideo\DefaultIcon]  
  6. @="C:\\Program Files\\MarkVideo\\MarkVideoTool.exe,1"  
  7. [HKEY_CLASSES_ROOT\MarkVideo\shell]  
  8. [HKEY_CLASSES_ROOT\MarkVideo\shell\open]  
  9. [HKEY_CLASSES_ROOT\MarkVideo\shell\open\command]  
  10. @="\"C:\\Program Files\\MarkVideo\\MarkVideoTool.exe\" \"%1\""  
 


5、调用

 

在jsp中 写成下面这样(MarkTool无关,写什么都行)

<li>
                             <a href="MarkVideo:MarkTool"><input size="0" name="markdata" value="视频标注模块" style="display:none"/><i class="fa fa-check-square-o nav_icon"></i>视频标注模块</a>
                        </li> 

 

来自CSDN博客:用jsp调用exe文 件http://blog.csdn.net/tjusxh/article/details/52162603

猜你喜欢

转载自it1990eye0920.iteye.com/blog/2323404
今日推荐