I'm trying to use the Google-Gson library with my Java project in Eclipse. In order to use the Mraa library I had to add the mraa.jar file, as well as use the following command in my code:
I'm assuming this line is looking for the shared object file libmraajava.so (correct me if I'm wrong), but I can't find anything like that for Google-Gson (files located at http://repo1.maven.org/maven2/com/google/code/gson/gson/2.5/ http://repo1.maven.org/maven2/com/google/code/gson/gson/2.5/).
I can use the Gson library in just a normal Java project by simply adding the Jar, but with the Edison I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/gson/Gson
Caused by: java.lang.ClassNotFoundException: com.google.gson.Gson
I've referenced the Jar as such:
Any help would be greatly appreciated! Thanks!
What Eclipse IDE have you downloaded? The Eclipse IDE from the Downloads section works for applications written in C and C++. The latest version is Luna SR2 (4.4.2). Are you trying to use Java code with this IDE?
And actually, it turns out I can get rid of the following line, and the Mraa library loads just fine.
Apparently importing the library into the build path is enough, so I have no idea what the System.loadLibrary call is doing. So I took that out.
UPDATE: I ended up with a workaround that isn't pretty, but I'll take it for now. Google has the source files available for their library, so I just added all the Java files from the Gson library directly into my project. I mean, that's basically what should be happening when I added the Gson Jar, so I'd still like to figure out why adding a third-party library via the .Jar won't work. I've tried with a couple different libraries and have yet to find success. None of the solutions I've found for a NoClassDefFound error have worked, and I'm sure I'm going to need another library in the future.
Any ideas why the libraries found in the IoT Sensor Support window will work when others won't?
Not sure why you are receiving that error, what command have you used to compile the Java files? The path seems to be correct; according to https://software.intel.com/en-us/node/596288 IoT - Running Java* IoT Applications outside of Eclipse* | Intel® Developer Zone the .jar files and Java shared libraries needed on runtime for using MRAA & UPM is /usr/lib/java.
Do you have the latest MRAA and UPM libraries installed?
That link is exactly what I needed! For anyone else using Java and Eclipse, Apparently adding the external JARs in Eclipse isn't enough, one also must copy the JARs over to the /usr/lib/java folder on the Edison (it's really easy using WinSCP). Once I did that, I no longer got my ClassNotFoundException during runtime.
Thanks so much for the help!