How to start the J-Integra Server programmatically and silently |
|
When accessing Java Server from .NET clients, you may want to start the J-Integra server programmatically and silently. That means no console window showing, J-Integra Server is invisible to users.
To start the J-Integra Server silently, you have to write a custom wrapper class to call com.intrinsyc.janet.control.Janet.init() and use command javaw instead of java to start the J-Integra Server.
An extremely simple custom wrapper class is provided below:
import com.intrinsyc.janet.control.*; import java.io.IOException;
public class Main { private Main() {} public static void main(String[] args) throws com.intrinsyc.janet.RemoteException { Janet.init(); } }
|
To start the J-Integra Server using above wrapper class:
javaw -cp $USER_INSTALL_DIR$\lib\janet.jar;. Main
However, if you use this way to start J-Integra Server, you have to manully kill its process from Windows Task Manager.
To start J-Integra Server programmatically, you can write a VB/C# program to start it at a process. The following is an example for this feature implemented in VB.NET.
Imports System Imports System.Diagnostics Imports System.ComponentModel
Namespace MyProcessSample Public Class MyProcess Private ERROR_FILE_NOT_FOUND As Integer = 2 Private ERROR_ACCESS_DENIED As Integer = 5 Private Sub runRegSvr32()
Dim myProcess As New Process Try myProcess.StartInfo.FileName = "javaw.exe" myProcess.StartInfo.Arguments = " -cp ""C:\Program Files\J-Integra\.NET\lib\janet.jar"";. Main" myProcess.StartInfo.CreateNoWindow = True myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden myProcess.StartInfo.UseShellExecute = False myProcess.StartInfo.RedirectStandardOutput = True myProcess.Start() 'myProcess.WaitForExit() 'myProcess.Dispose() Catch e As Win32Exception If e.NativeErrorCode = ERROR_FILE_NOT_FOUND Then Console.WriteLine((e.Message + ". Check the path.")) Else If e.NativeErrorCode = ERROR_ACCESS_DENIED Then Console.WriteLine((e.Message + ". You do not have permission to run this.")) End If End If End Try End Sub
Public Shared Sub Main() Dim myProcess As New MyProcess myProcess.runRegSvr32() End Sub End Class End Namespace
|
You can use above methods to start J-Integra Server programmatically and silently. You can also use the same way to distribute the server together with your program.