用jsp调用exe文件

来源:互联网 发布:数据库死锁解决 编辑:程序博客网 时间:2024/05/16 18:30

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


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)

 p.StartInfo.WorkingDirectory = "C:\\Program Files\\MarkVideo\\"; 这个是jar执行时候放在的目录。

using System;using System.Diagnostics;using System.Text.RegularExpressions;using System.Windows.Forms;namespace MarkVideoTool{    static class Program    {        /// <summary>        /// 应用程序的主入口点。        /// </summary>        [STAThread]        static void Main(string[] args)        {                        string cmd = "start javaw -jar MarkVideoTool.jar";            RunCmd(cmd);        }        private static void RunCmd(string command)        {            Process p = new Process();            p.StartInfo.WorkingDirectory = "C:\\Program Files\\MarkVideo\\";            p.StartInfo.FileName = "cmd.exe";            p.StartInfo.Arguments = "/c "+command;            p.StartInfo.UseShellExecute = false;            p.StartInfo.RedirectStandardInput = true;            p.StartInfo.RedirectStandardOutput = true;            p.StartInfo.RedirectStandardError = true;            p.StartInfo.CreateNoWindow = true;            p.Start();          //  p.StandardInput.WriteLine(command);          //  p.StandardInput.WriteLine("exit");          //  p.StandardOutput.ReadToEnd();            p.Close();        }    }}
3、把上面的jar、exe等其他关联文件放在 workingDirectory目录下。

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

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

Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOT\<span style="color:#ff0000;">MarkVideo</span>]"URL Protocol"="C:\\Program Files\\MarkVideo\\MarkVideoTool.exe"@="MarkVideoProtocol"[HKEY_CLASSES_ROOT\MarkVideo\DefaultIcon]@="C:\\Program Files\\MarkVideo\\MarkVideoTool.exe,1"[HKEY_CLASSES_ROOT\MarkVideo\shell][HKEY_CLASSES_ROOT\MarkVideo\shell\open][HKEY_CLASSES_ROOT\MarkVideo\shell\open\command]@="\"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> 


1 0
原创粉丝点击