Adding a custom library to Robot Code? (Java)

Hello all,

So we’ve written a library containing some basic items that we’ve used from year to year. However, I’m stuck trying to figure out how to add it to the actual robot code. I don’t want to add all of the files into the project itself, but, unlike with vanilla NetBeans projects, the robot project doesn’t have the feature to add libraries. Could anyone give any suggestions as to how to go about doing so?Thanks so much!

If you bundle it with the wpilibj source, you should be able to compile it and set it as the wpilibj file for your robot in the settings within net beans.

Go into the build.xml file and add something along the lines of the following code:


<exec executable="rm">
    <arg value="-rf" />
    <arg value="/path/to/robot/project/src/LibraryName" />
</exec>
<exec executable="cp">
    <arg value="-R" />
    <arg value="/path/to/library/src/org" />
    <arg value="src/" />
</exec>

This copies the library to the robot project’s src directory which makes it available during the build. The rm makes sure that the directory is updated every build, in case the library has changed. If you’re using windows, you’ll have to change the command names, but this should work on any Unix system.

Thanks this is exactly what I needed!

Remember that you’d need to post it publicly before build season for it to be used legally - that one almost got us this year. Good luck!

If you can, I’d recommend using GitHub – not only does it solve the releasing part (as you’d be open-sourcing it), but if you use Git during the year, you learn valuable skills widely used in industry.