ITeye博客

用jsp调用exe文件

it1990eye0920 · 2016-09-08 17:56 · Jquery、ajax、JavaScript · HTML · Web前端 · Markdown

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

 

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. namespace MarkVideoTool
  6. {
  7. static class Program
  8. {
  9. /// <summary>
  10. /// 应用程序的主入口点。
  11. /// </summary>
  12. [STAThread]
  13. static void Main(string[] args)
  14. {
  15. string cmd = "start javaw -jar MarkVideoTool.jar";
  16. RunCmd(cmd);
  17. }
  18. private static void RunCmd(string command)
  19. {
  20. Process p = new Process();
  21. p.StartInfo.WorkingDirectory = "C:\\Program Files\\MarkVideo\\";
  22. p.StartInfo.FileName = "cmd.exe";
  23. p.StartInfo.Arguments = "/c "+command;
  24. p.StartInfo.UseShellExecute = false;
  25. p.StartInfo.RedirectStandardInput = true;
  26. p.StartInfo.RedirectStandardOutput = true;
  27. p.StartInfo.RedirectStandardError = true;
  28. p.StartInfo.CreateNoWindow = true;
  29. p.Start();
  30. //  p.StandardInput.WriteLine(command);
  31. //  p.StandardInput.WriteLine("exit");
  32. //  p.StandardOutput.ReadToEnd();
  33. p.Close();
  34. }
  35. }
  36. }

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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。