using external libraries correctly

33 views
Skip to first unread message

Davide Cappellini

unread,
Apr 21, 2020, 2:54:46 PM4/21/20
to robocode-developers
Hello

I'm writing this again because I can't see the discussion I opened this morning (dunno what happened)
I will make this shorter with an example.

Suppose I want to use the external library ABC.jar in my robot.
Using an IDE like Eclipse you add the ABC.jar to the build path and is happy coding
When you run the robot in robocode application it fails because it can't find the ABC class, of course, Robocode doesn't see that library.
Questions:
  1. How do you make Robocode of the ABC library during development?
    I achieved this adding the jar file as argument to the launching command inside robocode.sh I'm happy whit this solution until I arrive to compile a nice jar to give to my friend, I can't create a working jar file.
  2. How do I create  a JAR file of my bot that includes the ABC library?
Thanks in advance

Flemming Larsen

unread,
Apr 21, 2020, 3:15:33 PM4/21/20
to robocode-developers
Hi David,

The reason why you and other people do not see the posts right away is that it needs to pass (manual) moderation first to prevent spam (like a lot of spam!)

The robot archiver for Robocode cannot include 3rd party libraries. It introduces security issues that are hard to tackle.

But you should be able to add the ABC.jar to the classpath of Robocode when running Robocode. That is the official way to do it. :-)
Then it is up to the user if he/she wants to "risk" adding the jar or not. Sometimes the security manager of Robocode needs to be turned off to use 3rd party libraries.

Cheers,
- Flemming


Davide Cappellini

unread,
Apr 21, 2020, 5:09:06 PM4/21/20
to robocode-developers
Thanks
I've realised my mistake about the post the moment I posted the second one, the first time I've missed the 1-second popup that informs about the approval requirement. My bad.

About the libraries, now that you mention the security issue, it makes sense. But was this since the same since ever? I've been mislead by a Talk on robowiki.net from 2013 where Skilgannon talks about using the Colt library, I wonder if that means that he was including the sources in the project and so compiling them within the robot itself, I don't even know if this is possible...

Cheers
Davide

Flemming Larsen

unread,
Apr 21, 2020, 5:18:28 PM4/21/20
to robocode-developers
Well, a robot/team jar file is just a zip file containing the class files, source files, and properties files. The properties file is meta-data about the robot or team used by Robocode.
So the jar file does not serve as a library like an executable jar file. Hence, it does not make sense to include other jar files, as Robocode is not extracting (embedded) jar files inside the robot/team jar files.

But you are right that you could add the sources of the library inside the robot. You simply add those sources to your robot project, compile all the code, and use the robot archiver as usual to create a robot archive. :-)

Note that you can use normal zip tools for opening the jar files to see what they contain (just rename the .jar into .zip). :-)

Cheers,
- Flemming

Davide Cappellini

unread,
Apr 23, 2020, 5:38:27 PM4/23/20
to robocode-developers
UPDATE
Today I've finally succeeded in using an external math library following the path of including the source code in the robot.
Extracting the classes from the jar is not more useful than using the jar directly, it work during development but does not inside the application or during the exportation of the robot.
Including the sources instead could result in a bit (or a lot) of work in solving all the dependencies issues but once done those are correctly compiled together with the robot code and included in the packaging of the robot later via the application tool.

Davide
Reply all
Reply to author
Forward
0 new messages