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