0
$\begingroup$

Rosanswers logo

Hi,

I've spent the last week learning gradle with little success. It seems overly complex and unnecessary for rosjava, but I will try to put my complaints aside. No matter what I do, after a gradle build (either using gradlew installApp or gradle build), my java class path is not set. I check my class path with echo $CLASSPATH and it always spits out a blank line. I even tried this from the pubsub tutorial and got the same result. This leads me to believe that it is normal behavior. However, if this is the case, how do you include dependencies? I follow the gradle default set up with my source code in main/src/main/java and my external .jar in src/main/resources, which gradle seems to use as the default (and I specify it in the gradle build script anyway for redundancy). Could someone please help?

src located in: /src/main/java/org/ros/rosd where org/ros/rosd is the package.

.jar in: /src/main/resources/d.jar

I know the jar runs fine, and after building I can manually run the java code: roscore & ./build/install/rosd/bin/rosd org.ros.rosd.talker & ./build/install/rosd/bin/rosd org.ros.rosd.listener &

However, whenever I try to initialize a constructor from something in the .jar, it fails to recognize it as an actual resource. For example, adding the following to talker.java: new ds(); throws a compile-time error. Though, I can manually run the jar with java -jar d.jar

edit: I should note that within talker.java I import edu.wpi.d; and it doesn't find the package, which is in d.jar.

Your help would be greatly appreciated!

--James


Originally posted by jforkey on ROS Answers with karma: 82 on 2013-02-26

Post score: 2

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I've solved this problem. If you want to define an external jar file located on your own system within gradle, it's as simple as adding:

compile files('libs/d.jar')

to the dependencies. So your dependencies look something like:

dependencies { compile 'ros.rosjava_core:rosjava:0.0.0-SNAPSHOT' compile files('libs/d.jar') }

An entire week on that tiny bit. At least I understand gradle dependencies quite well now.

Cheers, JAmes


Originally posted by jforkey with karma: 82 on 2013-02-26

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by Yeison Rodriguez on 2013-03-24:
Thanks James. I'm going to use this to add the slf4j logger to my classpath. I'm having some trouble building the rosjava build.

Comment by uzair on 2014-01-20:
i created another folder called lib in my package and put my jar in that lib folder. I aded this linein my build.gradle "compile files('lib/findtask-ros-1.0.0-SNAPSHOT.jar') " and so my dependencies looks like this "dependencies { compile project(':rosjava') compile files('lib/findtask-ros-1.0.0-SNAPSHOT.jar') } Is this all I need to do? Do I also need to include an import statement for the packages in this jar in my code?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.