/
runner.cs
72 lines (59 loc) · 2.19 KB
/
runner.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
// A few assembly level attributes.
[assembly:AssemblyVersion("2.0.0.0")]
[assembly:AssemblyProductAttribute("Runner")]
[assembly:AssemblyCopyrightAttribute("ope ltd")]
[assembly:AssemblyTitle("JAR Launcher")]
// NOTE: console output only shows if you run with | more option at cmd. eg runner.exe | more
namespace B4JRunner
{
class Program
{
static void Main(string[] args)
{
string ExeName = System.AppDomain.CurrentDomain.FriendlyName;
string JarName = ExeName.Replace(".exe",".jar");
string ThisLocation = Directory.GetCurrentDirectory();
string JavaFolder = "";
Console.WriteLine(ThisLocation);
// Updated the logic below, if there is a "private" runtime folder found then this will be the prefered one over the one in the C:\Java folder
// This is so that the runtime bundled with the app is used before looking for others
if(JavaFolder == "" && Directory.Exists(".\\runtime"))
{
JavaFolder = ".\\runtime\\java";
}
if(JavaFolder == "" && Directory.Exists("..\\runtime"))
{
JavaFolder = "..\\runtime\\java";
}
if(JavaFolder == "" && Directory.Exists(@"C:\Java"))
{
string [] subDirectories = System.IO.Directory.GetDirectories(@"C:\Java","*jdk*");
if (subDirectories.Length > 0)
{
string firstSubDir = subDirectories[0];
JavaFolder = firstSubDir;
}
}
Console.WriteLine(JavaFolder);
if (JavaFolder == "")
{
Console.WriteLine("Cant find runtime folder, exiting!");
Environment.Exit(-1);
}
//string Arguments = "--module-path " + JavaFolder + "\\javafx\\lib --add-modules javafx.controls,javafx.fxml -jar " + JarName;
string Arguments = "--module-path " + JavaFolder + "\\javafx\\lib --add-modules ALL-MODULE-PATH -jar " + JarName;
Console.WriteLine(Arguments);
Process p = new Process();
p.StartInfo.FileName = JavaFolder + "\\bin\\javaw.exe";
p.StartInfo.WorkingDirectory = ThisLocation;
p.StartInfo.Arguments = Arguments;
p.StartInfo.UseShellExecute = false;
p.Start();
p.WaitForExit();
}
}
}