This website uses browsing/session and functional cookies to ensure you get the best experience. Learn More

YARP and Java

From Wiki for iCub and Friends
Jump to: navigation, search

YARP supports Java via SWIG.

The way to do this is given in the example/swig directory.

Here are the basic steps:

  • Install the Java Development Kit
  • Install SWIG
  • Run ccmake or cmake in example/swig of the YARP directory.

Now we give brief instructions on how to achieve these steps on Windows, other OSes are either easier or analogous.

Contents

Installing Java on Windows

Installing SWIG on Windows

Run CMake

  • To help cmake find SWIG, you define a SWIG_DIR path.
  • If you have trouble, you can always click on "SHOW ADVANCED VALUES" and fill in SWIG-related fields that CMake couldn't figure out.

A transcript of a YARP/Java build, from scratch

[2:14:27 PM] YarpDev: I can talk you though it, if you want to do that...
[2:16:01 PM] JavaUser: ok, lets try it
[2:16:37 PM] YarpDev: Ok, I'll do the same steps on my machine.  Go into a new directory for this test.  Do:
[2:16:52 PM] YarpDev: svn co https://yarp0.svn.sourceforge.net/svnroot/yarp0/trunk/yarp2
[2:17:21 PM] YarpDev: when it is done, do:
[2:17:26 PM] YarpDev: mkdir build; cd build
[2:18:08 PM] YarpDev: ccmake ../yarp2
[2:18:15 PM] YarpDev: c to configure
[2:18:28 PM] YarpDev: turn on CREATE_SHARED_LIBRARY
[2:18:34 PM] JavaUser: ok,  its processing
[2:18:42 PM] YarpDev: c to configure
[2:18:50 PM] YarpDev: g to generate and exit
[2:18:54 PM] YarpDev: make
[2:19:50 PM] YarpDev: Let me know when you're done with that part...
[2:21:49 PM] JavaUser: done :)  it produced a few warnings though
[2:22:20 PM] YarpDev: Huh, can you paste the warnings?
[2:22:35 PM] JavaUser: [ 30%] Building CXX object src/libYARP_OS/CMakeFiles/YARP_OS.dir/src/Run.cpp.o                                                 
/opt/yarpTest/yarp2/src/libYARP_OS/src/Run.cpp: In static member function ‘static yarp::os::Bottle yarp::os::Run::ExecuteCmdAndStdio(yarp::os::Bottle&)’:                                                                                                     
/opt/yarpTest/yarp2/src/libYARP_OS/src/Run.cpp:1478: warning: format not a string literal and no format arguments              
/opt/yarpTest/yarp2/src/libYARP_OS/src/Run.cpp:1502: warning: format not a string literal and no format arguments              
/opt/yarpTest/yarp2/src/libYARP_OS/src/Run.cpp:1505: warning: format not a string literal and no format arguments              
/opt/yarpTest/yarp2/src/libYARP_OS/src/Run.cpp:1528: warning: format not a string literal and no format arguments              
/opt/yarpTest/yarp2/src/libYARP_OS/src/Run.cpp:1554: warning: format not a string literal and no format arguments              
/opt/yarpTest/yarp2/src/libYARP_OS/src/Run.cpp:1557: warning: format not a string literal and no format arguments              
/opt/yarpTest/yarp2/src/libYARP_OS/src/Run.cpp:1598: warning: format not a string literal and no format arguments              
/opt/yarpTest/yarp2/src/libYARP_OS/src/Run.cpp:1623: warning: format not a string literal and no format arguments              
/opt/yarpTest/yarp2/src/libYARP_OS/src/Run.cpp:1627: warning: format not a string literal and no format arguments              
/opt/yarpTest/yarp2/src/libYARP_OS/src/Run.cpp:1677: warning: format not a string literal and no format arguments              
/opt/yarpTest/yarp2/src/libYARP_OS/src/Run.cpp:1680: warning: format not a string literal and no format arguments              
/opt/yarpTest/yarp2/src/libYARP_OS/src/Run.cpp:1756: warning: format not a string literal and no format arguments              
/opt/yarpTest/yarp2/src/libYARP_OS/src/Run.cpp: In static member function ‘static yarp::os::Bottle yarp::os::Run::UserStdio(yarp::os::Bottle&)’:                                                                                                              
/opt/yarpTest/yarp2/src/libYARP_OS/src/Run.cpp:1792: warning: format not a string literal and no format arguments              
/opt/yarpTest/yarp2/src/libYARP_OS/src/Run.cpp:1831: warning: format not a string literal and no format arguments              
/opt/yarpTest/yarp2/src/libYARP_OS/src/Run.cpp:1834: warning: format not a string literal and no format arguments              
/opt/yarpTest/yarp2/src/libYARP_OS/src/Run.cpp:1871: warning: format not a string literal and no format arguments              
/opt/yarpTest/yarp2/src/libYARP_OS/src/Run.cpp: In static member function ‘static yarp::os::Bottle yarp::os::Run::ExecuteCmd(yarp::os::Bottle&)’:                                                                                                             
/opt/yarpTest/yarp2/src/libYARP_OS/src/Run.cpp:1908: warning: format not a string literal and no format arguments              
/opt/yarpTest/yarp2/src/libYARP_OS/src/Run.cpp:1943: warning: format not a string literal and no format arguments              
/opt/yarpTest/yarp2/src/libYARP_OS/src/Run.cpp:1948: warning: format not a string literal and no format arguments              
/opt/yarpTest/yarp2/src/libYARP_OS/src/Run.cpp:1986: warning: format not a string literal and no format arguments              
[ 31%] Building CXX object src/libYARP_OS/CMakeFiles/YARP_OS.dir/src/McastCarrier.cpp.o
[2:23:16 PM] YarpDev: Ok, I'm copying that to pass on to the Run.cpp guy :-) but that code isn't important for any of this.
[2:23:31 PM] JavaUser: heheh.. ok then :)
[2:23:46 PM] YarpDev: okay, do either
[2:23:50 PM] YarpDev: export YARP_DIR=$PWD
[2:23:51 PM] YarpDev: or
[2:23:56 PM] YarpDev: setenv YARP_DIR $PWD
[2:24:05 PM] YarpDev: whichever works (depends on your shell)
[2:24:12 PM] YarpDev: then:
[2:24:14 PM] YarpDev: cd ..
[2:24:21 PM] YarpDev: mkdir java; cd java
[2:24:57 PM] JavaUser: done
[2:25:07 PM] YarpDev: ccmake ../yarp2/example/swig/
[2:25:13 PM] YarpDev: c
[2:25:17 PM] YarpDev: CREATE_JAVA on
[2:25:26 PM] YarpDev: c
[2:25:42 PM] YarpDev: if everything is ok, g to generate.
[2:26:04 PM] YarpDev: Did it pick up your Java-related headers ok? any NOTFOUNDs?
[2:26:41 PM] JavaUser: no error messages until now
[2:26:49 PM] YarpDev: ok, then:
[2:26:50 PM] YarpDev: make
[2:27:07 PM] YarpDev: Do you get a libjyarp.so?
[2:27:38 PM] JavaUser: yes
[2:27:42 PM] JavaUser: there it is
[2:27:43 PM] JavaUser: :)
[2:27:54 PM] YarpDev: Good.  The next steps will be a bit inelegant :-)
[2:28:00 PM] JavaUser: ehhehe
[2:28:01 PM] YarpDev: cd generated_src
[2:28:06 PM] YarpDev: cp ../libjyarp.so .
[2:28:30 PM] YarpDev: cp ../../yarp2/example/swig/src/*.java .
[2:28:46 PM] YarpDev: export LD_LIBRARY_PATH=$PWD
[2:29:05 PM] YarpDev: javac *.java
[2:29:27 PM] YarpDev: ln -s $PWD yarp
[2:29:46 PM] YarpDev: java Example1
[2:30:18 PM] JavaUser: hummmmmm
[2:30:23 PM] JavaUser: sending bottle
[2:30:34 PM] YarpDev: sending bottle: 10.4 bozo?
[2:30:43 PM] JavaUser: yes
[2:30:47 PM] JavaUser: root@tenorio:/opt/yarpTest/java/generated_src# java Example1
yarp: No connection to nameserver
yarp: *** try running: yarp detect ***
yarp: Port /foo failed to activate (invalid address)
yarp: No connection to nameserver
yarp: *** try running: yarp detect ***
sending bottle: 10.4 bozo
sending bottle: 10.4 bozo
sending bottle: 10.4 bozo
sending bottle: 10.4 bozo
sending bottle: 10.4 bozo
sending bottle: 10.4 bozo
sending bottle: 10.4 bozo
sending bottle: 10.4 bozo
sending bottle: 10.4 bozo
^Croot@tenorio:/opt/yarpTest/java/generated_src#
[2:31:12 PM] YarpDev: Ah, start a yarp server in another terminal (fine to use old yarp version)
[2:31:32 PM] YarpDev: then retry "java Example1"
[2:32:10 PM] YarpDev: To start a yarp server, run "yarp server" or "yarpserver"
[2:32:31 PM] JavaUser: it appears there
[2:32:34 PM] JavaUser: like this
[2:32:37 PM] JavaUser: yarp: Port /root active at tcp://99.88.77.66:10000
yarp: Name server can be browsed at http://99.88.77.66:10000/
yarp: Bootstrap server listening at mcast://224.2.1.1:10001
yarp: registration name /foo ip 99.88.77.66 port 10002 type tcp
yarp: port /foo property offers = tcp text text_ack udp mcast shmem name_ser
yarp: port /foo property accepts = tcp text text_ack udp mcast shmem name_ser
yarp: port /foo property ips = 127.0.0.1 99.88.77.66 ::1 fe80::222:15ff:febf:5338%2
yarp: port /foo property process = 10735
yarp: ok
yarp: registration name /foo ip 99.88.77.66 port 10002 type tcp
yarp: *** end of message
[2:32:52 PM] YarpDev: And does "java Example1" look right now?
[2:33:05 PM] JavaUser: same thing
[2:33:07 PM] YarpDev: $ java Example1
yarp: Port /foo active at tcp://192.168.1.3:10002
sending bottle: 10.4 bozo
sending bottle: 10.4 bozo
sending bottle: 10.4 bozo
[2:33:21 PM] JavaUser: ah
[2:33:22 PM] JavaUser: yes
[2:33:32 PM] JavaUser: ^Croot@tenorio:/opt/yarpTest/java/generated_src# java Example1
yarp: Port /foo active at tcp://99.88.77.66:10002
sending bottle: 10.4 bozo
sending bottle: 10.4 bozo
sending bottle: 10.4 bozo
sending bottle: 10.4 bozo
^Croot@tenorio:/opt/yarpTest/java/generated_src#
[2:33:35 PM] YarpDev: Ok!  It works :)
[2:33:38 PM] JavaUser: hehehe
[2:33:44 PM] JavaUser: cool
[2:33:47 PM] JavaUser: thank you paul
[2:33:56 PM] YarpDev: no problem...
[2:34:05 PM] JavaUser: But I missed to understand what the problem was
[2:34:19 PM] YarpDev: Me too.
[2:34:24 PM] JavaUser: :D
[2:34:51 PM] YarpDev: I was seeing a problem with yarp-2.2.6, although it wasn't exactly like yours - but then I have a slightly different java build
[2:35:09 PM] JavaUser: yes..  mine is build 20
[2:35:18 PM] JavaUser: my friend's build is 18
[2:36:10 PM] YarpDev: Ok.  Well you could try updating your machine's yarp version to trunk (or 2.3.0) and see how it goes...
[2:37:45 PM] YarpDev: I don't suppose you'd be ok with me taking this chat transcript, anonymizing it, and posting the build instructions on the YARP/java wiki page?  I don't know if it is the best method but it is one method...
[2:38:09 PM] JavaUser: I was about to suggest that :)
[2:38:19 PM] YarpDev: :) good, will do then
[2:38:35 PM] YarpDev: I'd better run, let me know how it goes...
[2:38:46 PM] JavaUser: Sure.. thanks a lot !
[2:38:57 PM] YarpDev: no problem.  bye :-)
[2:39:08 PM] JavaUser: bye
Personal tools
Namespaces

Variants
Actions
Navigation
Print/export
Toolbox