I accomplished this with a little bit of help from my assistant, ChatGPT. Here is a java program that will launch a jar using only the java.io package.
import java.io.*;
class JarLauncher {
public static void main(String[] args) {
Process jarProcess = null;
try {
// Define the directory path without the JAR file name
String directoryPath = "FILE_PATH_TO_YOUR_OSBOT.JAR_FILE";
// Set the working directory to the correct directory and launch the osbot.jar jar file (rename if needed)
ProcessBuilder processBuilder = new ProcessBuilder("java", "-jar", "osbot.jar",
"-login", "osbot_username:osbot_password",
"-bot", "account_name:account_password:0000",
"-script", "Extra House Favour:hosidius_1"
);
processBuilder.directory(new File(directoryPath));
// Start the process
jarProcess = processBuilder.start();
// Capture the process output for logging
BufferedReader reader = new BufferedReader(new InputStreamReader(jarProcess.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
// Count the seconds
int seconds = 0;
// Run the Java program for 3 seconds
while (seconds < 3) {
// Wait for 1 second
Thread.sleep(1000);
seconds++;
System.out.println("Running for " + seconds + " seconds.");
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
} finally {
if (jarProcess != null) {
try {
// Terminate the JAR process
jarProcess.destroy();
int exitCode = jarProcess.waitFor();
System.out.println("JAR process exited with code: " + exitCode);
// Optionally, use taskkill to forcefully terminate the JAR process
String os = System.getProperty("os.name").toLowerCase();
if (os.contains("win")) {
Runtime.getRuntime().exec("taskkill /F /IM java.exe");
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
// Exit the Java application when done
System.exit(0);
}
}
}