I have been writing some Java software in VSCode that should be able to run on any computer, however it uses some of the WPILib functions. It currently sits in a VSCode project along with our robot code, but I really need to separate it into its own project. I have just been running it from within VSCode by right-clicking in the mainclass and selecting “Run java”.
I have tried creating a new Java project in VSCode, but it doesn’t link in the WPILib libraries.
I am very familiar with Eclipse (have used it for about 20 years at work) and its build and having a “libs” directory with jar files and linking them to the build path, but cannot seem to find anything like this in VSCode for the WPILib jars (I assume that there are also some dlls or similar for the JNI parts). I somehow need to both get these (jars and dlls) into my new project, as well as package them up to distribute to whichever computers run my application.
The only things I can find to create new projects are all based around various types of robots (timed or command) and are not really what I am after.
Does anyone have any pointers to a tutorial on how to create a project in VSCode that links to the WPILib library?
What wpilib functions are you using? Most are robot-centric and use the HAL, so they would need the robot (or simulation) to work. If we’re just talking networktables functionality (or smart dashboard/shuffleboard/etc), then those libraries can be pulled into your other project by a dependency definition in your build.gradle (or pom.xml if you want to use maven instead of gradle).
The only other thing you should need is a repository definition so it knows where to pull from, because wpilib doesn’t publish to maven central. I’ll let someone else answer what URI that repository definition should point to as I’m not sure offhand.
From there, it’s just a Java project, so you’d configure the build script to build out a jar that you can run wherever you need.
This particular project uses the new WPILog functions from WPILib, although I have plans for a couple that use NetworkTables as future projects.
I found some repository locations listed in the following webpage, however it talks about adding them to a section in build.gradle, but I can’t find that file when I create a new project.
As far as building a jar file, wouldn’t I also need the compiled JNI libraries (dll files?) as WPILib is not pure java?
WPILib is a collection of projects, with the HAL being one of them. Again, someone else can correct me if I’m wrong, but I believe the HAL is the only one making use of JNI. Assuming that’s accurate, you would only need that if you’re using the HAL, which would only be needed on the rio itself (or sim).
Other components include ntcore (network tables), cscore (camera server), etc. I’m not (yet) familiar with WPILog, so I can’t say where that lives specifically, but should be easy enough to figure out looking at the source in github. They’re pretty good about maintaining the project directory structure.
As for the missing build.gradle, you probably created a maven project instead. In that case, you would create a repository block in the pom.xml file instead.
A large portion of the API library is actually JNI wrappers around the C++ implementation. So this isn’t super true.
Thanks for spending the time looking at this!
I had a look into the WPILog libraries and they appear to all be native Java, so that should make it a bit easier for this particular project. Looking inside the NetworkTables implementation I found a huge pile of JNI calls, so that is going to require some DLLs or something from somewhere.
As far as setting up to link in those WPILib libraries, I am still trying to figure out how to do this. I have looked at some tutorials that say to install “Gradle for Java” and then click on the elephant icon, however after installing Gradle for Java I do not get an elephant icon in my project (although it appears if I load my team’s robot code). I also suspect that I am going in the wrong direction as all the gradle build stuff is working for the robot code without needing a separate install of Gradle for Java, I just have no clue how to activate it in my project.
Is there a tutorial around somewhere that shows how to write your own code linking to the WPILib libraries (that doesn’t involve creating robot.java)?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.