Sorry I could not find a newbee group to post in. I have little to no experience with Java. You can call me a "learn as I go" dabbler.
I find it makes much more sense to me if I just try to figure out what it is I need to do rather than learning how to program the space shuttle!

I am "dabbling" with an evaluation copy of a Apache-Tomcat based application. Out of the box it works as advertised. Now I want to
add a little modification that saves a Javascript variable out to a database. In this case Mongo. I have the javascript code and the variable.

I got a basic connection java file to work (see below). Now I need to get it to accept the javascript variable and store it out to Mongo.

I will make this short.

I am using command line for everything I do, so no IDE.

So I have a java file that I compile like this with no errors:

javac -cp .:bson-3.9.1.jar:mongo-java-driver-3.9.1.jar:mongodb-driver-core-3.9.1.jar:mongodb-driver-3.9.1.jar
And I run it like this with no errors:

java  -cp .:bson-3.9.1.jar:mongo-java-driver-3.9.1.jar:mongodb-driver-core-3.9.1.jar:mongodb-driver-3.9.1.jar ConnectToDB
Here is the out put:

Jul 02, 2019 11:29:53 AM com.mongodb.diagnostics.logging.JULLogger log 

INFO: Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}

Connected to the database successfully 

Credentials ::MongoCredential{
Up to this point the java works fine with mongo.

So, first question: Is there a better (shorter) way to execute the runtime rather than including all of the .jar files?

Second question: How can I configure the file so I can pass the javascript variable to it and then save it out to the database?
A subsequent client will have to do the opposite and read it out of the Mongo db and save it to a javascript variable.
I've been thinking servlet, but the more I research that method, the more confused I get!

Thanks in advance for your help!