Ask coding questions

← Back to all posts
How to call .jar from .js
PowerGuy3478 (0)

I am attempting to host a bot jar on I have made an express webserver, and the run is set to launch it, I simply need help on getting the webserver code to call the .jar when it is ready. (I am a very new coder, so sorry if this is obvious.)

Answered by EpicGamer007 (1736) [earned 5 cycles]
View Answer
EpicGamer007 (1736)

You could do what @SixBeeps said or you could do something like

const { spawn } = require("child_process");
const { join } = require("path");

const bot = spawn('java', ["-jar", join(__dirname, "JMusicBot-0.3.4.jar")]);
SixBeeps (5234)

@EpicGamer007 To be honest, I'd avoid that altogether to avoid multiple servers.

EpicGamer007 (1736)

@SixBeeps agreed, honestly, if the OP wanted to setup a pinging service, they could make a server in java itself

SixBeeps (5234)

I'd imagine if the bot was provided to you in a .jar that it starts its own server, meaning you wouldn't need to set one up. The setup page for this bot doesn't mention anything about setting one up, so I'd recommend not having one unless you plan on using UptimeRobot.

I was able to start the jar with the typical java -jar JMusicBot-0.3.4.jar, so give that a try.

PowerGuy3478 (0)

@SixBeeps Uptime robot is what I am planning on using, and I know I can call the bot like that from the terminal, but I need to find a way for the keep_run.js to call the .jar after it has initialized. Simply typing that into the file doesn't seem to work.