ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Rosjava gradle build java classpath

asked 2013-02-26 02:17:10 -0600

jforkey gravatar image

updated 2013-04-28 23:15:46 -0600

ipso gravatar image


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 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 I import edu.wpi.d; and it doesn't find the package, which is in d.jar.

Your help would be greatly appreciated!


edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-02-26 03:43:01 -0600

jforkey gravatar image

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

edit flag offensive delete link more


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.

Yeison Rodriguez gravatar image Yeison Rodriguez  ( 2013-03-24 23:47:57 -0600 )edit

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?

uzair gravatar image uzair  ( 2014-01-20 14:06:26 -0600 )edit

answered 2017-02-13 00:08:21 -0600

Using wildcards in java classpath

Wild cards were introduced from Java 6. Class path entries can contain the basename wildcard character *, which is considered equivalent to specifying a list of all the files in the directory with the extension .jar or .JAR. For ex. a classpath entry consisting simply of * expands to a list of all the jar files in the current directory.


java -cp "lib/*" %MAINCLASS% where %MAINCLASS% is the class containing your main method.

How to use a wildcard in the classpath to add multiple jars

java -cp "lib/*" -jar %MAINJAR%

where %MAINJAR% is the jar file to launch via its internal manifest.

If you need only specific jars, you will need to add them individually. The classpath string does not accept generic wildcards like Jar, *.jar, hiber etc.


The following entry does not work:

java -cp "Halo.jar;lib/*.jar" ni.package.MainClass

Correct entry is :

java -cp "Halo.jar;lib/*" ni.package.MainClass

More about....Java Classpath


edit flag offensive delete link more

Question Tools


Asked: 2013-02-26 02:17:10 -0600

Seen: 1,517 times

Last updated: Feb 13 '17