html实现调用jar包


整体思路:html引用URL protocol-本地注册表key,key对应某一c#写的exe可执行文件,由exe可执行文件调用cmd,cmd执行jar包。

1、添加注册表:

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Print]
"URL Protocol"="d:\\Print\\SupplementPrint.exe"
@="PrintProtocol"
[HKEY_CLASSES_ROOT\Print\DefaultIcon]
@="d:\\Print\\SupplementPrint.exe,1"
[HKEY_CLASSES_ROOT\Print\shell]
[HKEY_CLASSES_ROOT\Print\shell\open]
[HKEY_CLASSES_ROOT\Print\shell\open\command]
@="\"d:\\Print\\SupplementPrint.exe\"\"%1\""

说明:第一行,注册版本信息,无需关注;2,、注册表中key值,html中也需要引用这个key“Print”,3、此key对应的exe文件。4、协议名称。。。

2、编写C#调用cmd.exe,cmd再调用jar包。

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Windows.Forms;
 5 using System.Diagnostics;
 6 using System.Text.RegularExpressions;
 7 
 8 
 9 namespace WindowsFormsApplication1
10 {
11     static class Program
12     {
13         /// <summary>
14         /// 应用程序的主入口点。
15         /// </summary>
16         [STAThread]
17         static void Main()
18         {
19             //string fullPath = System.Windows.Forms.Application.ExecutablePath;
20             //System.Console.WriteLine("Hello world");
21             //System.Console.WriteLine(fullPath);
22             //string fileName = System.IO.Path.GetFileName(fullPath);
23             //string folderPath = fullPath.Substring(0,fullPath.Length-fileName.Length);
24             //string cmd = "start " + folderPath + " jre/bin/javaw - jar " + folderPath + "zte-mes-supplementPrint-javaFX-0.0.1-SNAPSHOT.jar";
25             //System.Console.WriteLine(cmd);
26             RunCmd(cmd);
27         }
28 
29         private static void RunCmd(string cmd)
30         {
31             Process p = new Process();
32             p.StartInfo.FileName = "cmd.exe";
33            
34             p.StartInfo.UseShellExecute = false;
35             p.StartInfo.RedirectStandardInput = true;
36             p.StartInfo.RedirectStandardOutput = true;
37             p.StartInfo.RedirectStandardError = true;
38             p.StartInfo.CreateNoWindow = true;
39             //string str = Console.ReadLine();
40             string str = @"java -jar c:\\Users\\10244896\\Desktop\\print\\zte-mes-supplementPrint-javaFX-0.0.1-SNAPSHOT.jar" + "&exit";
41             str = str.Trim().TrimEnd('&');
42             p.Start();
43             p.StandardInput.WriteLine(str);
44 
45             p.StandardInput.AutoFlush = true;
46             //p.StartInfo.Arguments = "java -jar c:\\Users\\10244896\\Desktop\\print\\zte-mes-supplementPrint-javaFX-0.0.1-SNAPSHOT.jar";
47             
48             
49             p.WaitForExit();
50            // throw new NotImplementedException();
51         }
52     }
53 }

说明:仅关注runCmd方法即可。

3、编写html

<a href="Print://hello">Print</a>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM