I have the programming game 'Robocode' in my project root so I can run the project anywhere and not have it installed in C:/robocode. I have a run configuration with the following options;
- Main Class: robocode.Robocode
- VM Options: -Xmx512M -Dsun.io.useCanonCaches=false -Ddebug=true -DNOSECURITY=true -cp libs/robocode.jar
- Working directory: MY_ROOT\robocode_master
- JRE: Default(9.0.1 - SDK of my main module)
I'm writing some custom functionality for an AdvancedRobot that connects to a MongoDBAtlas Cluster for necessary data. I'm using mongo-java-driver-3.6.1. The .jar has been added as a library to IntelliJ, then as a compile dependency on the main module. It works fine in testing, I can download documents etc.
To illustrate, the libraries are shown here in the Project structure pane.
I have set the compile output path to the robocode_master/robots directory so that when I run Robocode from IntelliJ, it will see the custom robot .class files in the correct directory and allow me to add them to a battle.
The problem is when I start the battle and the robot tries to do what it needs to do, it throws a java.io.FileNotFoundException and is trying to find the necessary library files from the robocode_master/robots directory.
For example, the first thing it does is connect to the DB;
java.io.FileNotFoundException: MY_ROOT\robocode_master\robots\com\mongodb\MongoClient.class (The system cannot find the path specified)
When I have my project output paths set to the robots folder, upon launching Robocode, it throws a bunch of FileNotFoundExceptions. But if I switch the options to 'Inherit project compile output path', then launch Robocode, I don't get the exceptions upon launch. But now of course, my robots aren't in the default directory, so it can't see them. So I add the new path in out/production/... to Robocode in the GUI and reboot, and I then get the same exceptions from the robots. It now tries to look for the files in out/production/.../com/mongodb/MongoClient.class
How can I 'tell' Robocode to look for the libraries in their default location on the classpath?

Robocode will look for robot classes in your /robots folder. If your robot is located somewhere else, you need to tell Robocode where to locate these from the Robocode UI by setting with the Developments Options. Robocode has it's own class loader for loading Robot classes - but only robot classes.
Other classes/libraries must be specified on the ordinary classpath for Robocode using the -cp or -classpath for the java command (VM Options) like done for any other Java application.
Also notice, that you should use the VM Options that comes with Robocode - like the ones specified in the robocode.bat file. Especially when you use Java 9 or newer:
You could copy this into "run_my_stuff.bat" and add stuff to the -cp right after libs/robocode.jar.
However, I am not sure if it will work with the Mongo driver. Robocode was built for simple robots with limited access to resources like CPU cycles, file access etc.