# ROSJAVA and External Libraries (again)

Dear all,

I try to include an external library to the example of rosjava_tutorial_pubsub_Listener.

I modified the code as follows:

 package org.ros.tutorials.pubsub;
import org.apache.commons.logging.Log;
import org.ros.message.MessageListener;
import org.ros.namespace.GraphName;
import org.ros.node.Node;
import org.ros.node.NodeMain;
import org.ros.node.topic.Subscriber;
import cylinder_reasoner.*;

/**
* This is a simple rosjava {@link Subscriber} {@link Node}. It assumes an
* external roscore is already running.
*
*/
public class Listener implements NodeMain {

@Override
public GraphName getDefaultNodeName() {
return new GraphName("rosjava_tutorial_pubsub/listener");
}

@Override
public void onStart(Node node) {
final Log log = node.getLog();
CylinderReasoner reasoner=new CylinderReasoner();
reasoner.doReasoning("//home//eich//Cylinders.txt");

Subscriber<org.ros.message.std_msgs.String> subscriber =
node.newSubscriber("chatter", "std_msgs/String");
{
@Override
public void onNewMessage(org.ros.message.std_msgs.String message) {
log.info("I heard: \"" + message.data + "\"");
}
});
}


Than I added the following line to the manifest.txt

<rosjava-pathelement location="/home/eich/Test.jar" />


Test Test.jar contains the Package cylinder_reasoner.CylinderReasoner.

Problem is I cannot compile. The error is that

Listener.java:25: package cylinder_reasoner does not exist

Do I have to set the jar file somewhere else as well? Or only in the manifest. After calling rosmake, the .classpath is updated correctly, but it cannot find the package.

Do you have any ideas?

Thank you

edit retag close merge delete

Sort by » oldest newest most voted

I solved the problem by adding the needed jars files to the ros.properties. This seems to work. The problem is I have to add them every time I call rosmake.

more

Sounds like a bug. I've filed this issue: http://code.google.com/p/rosjava/issues/detail?id=85
( 2012-02-02 02:01:30 -0500 )edit

I also tried to use relative path (i.e. the jars are in the root directory of the rosjava project). They are not added to ros.properties either.

( 2012-02-15 03:47:46 -0500 )edit

Thanks for the answer. I tried both eclipse and ant. Ant gives a compile error

Compiling 1 source file to /home/eich/dev/rosjava_core/rosjava_tutorial_pubsub/target/classes
[javac] Listener.java:25: package cylinder_reasoner does not exist
[javac] import cylinder_reasoner.*;


Although I set up the path to my Test.jar in the manifest. I run make in the project folder and get a compile error.

When I try to run the project in Eclipse (which I would prefere) I get another error Usage: rosrun rosjava_bootstrap run.py org.foo.MyNode [args] __name:=<node name="">

How can I setup Eclipse to run the node? I tried to enter rosjava_tutorial_pubsub org.ros.tutorials.pubsub.Listener in the arguments list. Than I get another error

Loading node class: rosjava_tutorial_pubsub
Exception in thread "main" org.ros.exception.RosRuntimeException: Unable to locate node: rosjava_tutorial_pubsub
at org.ros.RosRun.main(RosRun.java:64)
Caused by: java.lang.ClassNotFoundException: rosjava_tutorial_pubsub
`
more

I just realized that my Test.jar is NOT included in the ros.properties after calling make. Shouldn't it be there after calling make? Where is the information stored where <rosjava-pathelement location="/home/eich/Test.jar"/> is pointing to?

Cheers,

Markus

more

How are you compiling? Eclipse? Ant?

After modifying the manifest.xml, you'll need to run make in the package to update the ant scripts. After you've run make, you can then skip running make in the future and just compile with either ant or Eclipse. Skipping make is faster.

more