B4J Question JettyServer Tray Icon App

tchart

Well-Known Member
Licensed User
Longtime User
You can "restart" the server this way;

B4X:
Dim jo As JavaObject = webserver
jo.GetFieldJO("server").RunMethod("stop", Null)

webserver.Start

But what are you actually trying to achieve? Are you just wanting to stop the web server, terminate the app or restart the app?

For example I have a jServer app that restarts itself every 24 hours. This is done using a service wrapper - the app tells the service wrapper to close and restart the app.
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
But what are you actually trying to achieve?
I'm developing an app and have to debug it a numerous times before it reaches maturity. This means running the app, testing it, over and over again.

Now with a jServer based app, the instance runs up until you "end process" via the task bar. A tray icon perhaps could be advantageous as one would just end the task there without having to open the task bar, locate the instance and then "end process"

For example, MySQL has a Notifier App that one can download and install. With this one is able to stop and start the server.

1610059424271.png


This is what is on my mind. Thanks.
 
Upvote 0

tchart

Well-Known Member
Licensed User
Longtime User
You need jFX for the icontray so it wont play nice with jServer.

I had to do something with PowerShell recently (it was running a web server). I added a route to the web server that shut the web server down when I called that route (eg http://server/shutdown). Would that work for you? Thats what @Erel was suggesting.

Just have a handler call this Sub in Main

B4X:
Sub StopTheApp  
    StopMessageLoop
    ExitApplication
End Sub
 
Last edited:
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
It's no too hard to use awt.SystemTray (I have not used JSystemTray - I did it the old fashioned way lol - java code)
1610082640568.png
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Sorry for the formatting - the paste seems to have removed all the tabs.
B4X:
' inline java "doit()" called before starting server
...
Sub stoppit ' called from java code
StopMessageLoop
ExitApplication
End Sub
...
#if java
import java.awt.*;
import java.awt.event.*;

public static void doIt(){
TrayIcon trayIcon = null;
if (SystemTray.isSupported()) {

SystemTray tray = SystemTray.getSystemTray();

Image image = Toolkit.getDefaultToolkit().getImage("c:/temp/hannah.jpg");

if (image==null) System.out.println("image error");
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Closing the server");
try{
_stoppit();
} catch (Exception ure){
}
}
};
PopupMenu popup = new PopupMenu();

MenuItem defaultItem = new MenuItem("Shutdown Server");
defaultItem.addActionListener(listener);
popup.add(defaultItem);

trayIcon = new TrayIcon(image, "Server Control", popup);

trayIcon.addActionListener(listener);

try {
tray.add(trayIcon);
} catch (AWTException e) {
System.err.println(e);
}

} else {
System.out.println("Can't sccess systemtray");
}
}
#End If
 
Upvote 0

Similar Threads

Top