I am trying to make a library of various classes my team has made during the off season which we think will be useful in the future. Rather than having to copy the classes into each new project (potentially causing the versions in older code to become outdated), we would like to create a library on our github that we could put into every robot project we make. So far I have been able to create a .jar file that can be imported into a normal java project, but when I try to put it into a FRC project it does not allow me to use the contained classes. Is there any way that I could make this work?
Can you post an image of what you’re seeing when you add the .jar to the FRC project? Also, I will bring up the fact that you’re not allowed to use or reuse code made before the build season without making it publicly available to whoever wants it.
“Software and mechanical/electrical designs created before Kickoff are only permitted if the source files (complete information
sufficient to produce the design) are available publicly prior to Kickoff.” - Rule 13, Section 4 - The Robot, page 34 of the Game Manual.
This is possible to do. As part of beta testing last year, we built a library for controlling swerve drive (not completely finished and not ready for prime time yet), included it in a robot project, and pushed everything to the roboRIO.
Build the library as a jar, and include it as a dependency in the eclipse project. That’ll make eclipse happy so you don’t get a bunch of errors.
The key for getting it to the roboRIO is the config file that’s used to build everything. I can copy in an example tonight from our build space… Basically, the file contains a list of jars (among other things) to include (wpilib.jar, etc), and you need to include your custom jar in the list. Pretty simple once you know how to do it, and if you update the jar it’ll automatically be included the next time you deploy.
As promised… when you create your Java project, you should see a build.properties file. Open that up, and you’ll see something similar to:
Project specific information
package=org.usfirst.frc.team2177.robot
robot.class=${package}.Robot
simulation.world.file=/usr/share/frcsim/worlds/GearsBotDemo.world
To get the jar’s copying to the roboRIO correctly, add a line for the classpath and include all jars (including wpilib and networktables!):
Project specific information
package=org.usfirst.frc.team2177.robot
robot.class=${package}.Robot
simulation.world.file=/usr/share/frcsim/worlds/GearsBotDemo.world
classpath=…/WPILib.jar:…/NetworkTables.jar:…/minnesota_swerve.jar
Please note that the classpath needs the correct path to each jar file - in this example, we had copied out the WPILib and NetworkTables jars to someplace a little easier for us to reference than the default location. The relative path is from the project folder. I’ve bolded the custom jar we added.