## For instruction on writing tutorials ## http://www.ros.org/wiki/WritingTutorials #################################### ##FILL ME IN #################################### ## for a custom note with links: ## note = ## for the canned note of "This tutorial assumes that you have completed the previous tutorials:" just add the links ## note.0=[[rosjava/Tutorials/indigo/Installation|Installation]] ## note.1=[[rosjava_build_tools/Tutorials/indigo/Creating Rosjava Packages|Creating Rosjava Packages]] ## descriptive title for the tutorial ## title = Building RosJava Libraries (Catkin Style) ## multi-line description to be displayed in search ## description = How to create, compile and deploy rosjava libraries (maven artifacts). ## the next tutorial description (optional) ## next = ## links to next tutorial (optional) ## next.0.link=[[rosjava/Tutorials/indigo/RosJava Message Artifacts|RosJava Message Artifacts]] ## next.1.link= ## what level user is this tutorial for ## level= BeginnerCategory ## keywords = rosjava #################################### <> <> This tutorial describes how to create and deploy rosjava libraries (jars) along with an explanation of the mysterious process itself. It assumes that you have a ros-catkin environment from a [[rosjava/Tutorials/indigo/Installation|source or deb installation]] and have skimmed through the [[rosjava_build_tools/Tutorials/indigo/Creating Rosjava Packages|creating rosjava packages tutorial]]. == Building the Jar == === Creating a Gradle Sub-Project === This assumes you have already initialised a catkin-gradle package for your java projects. If you haven't done so already, refer to the [[rosjava_build_tools/Tutorials/indigo/Creating Rosjava Packages#RosJava_Catkin_Packages|Creating Rosjava Packages]] tutorial. A catkin_create wizard is available that automagically creates a gradle subproject with the appropriate structure and a dummy class for a library jar. {{{ > source devel/setup.bash > cd src/rosjava_catkin_package_a > catkin_create_rosjava_library_project my_java_library > cd ../.. > catkin_make }}} You should see it work through the gradle tasks and finally dump the resulting artifact (jar) in our local workspace maven repository (`devel/share/maven`). {{{ :my_java_library:generatePomFileForMavenJavaPublication :my_java_library:compileJava :my_java_library:processResources UP-TO-DATE :my_java_library:classes :my_java_library:jar :my_java_library:publishMavenJavaPublicationToMavenRepository Uploading: com/github/rosjava/rosjava_catkin_package_a/my_java_library/0.1.0/my_java_library-0.1.0.jar to repository remote at file:~rosjava_workspace/devel/share/maven/ }}} The actual .jar that resulted from the build process before uploading can be found in `my_java_library/build/libs`. == Under the Hood == === The Gradle Task === When you run catkin_make, cmake runs through your entire workspace and when it gets to your new project, it will pass off the build to gradle. The tasks that gradle builds can be seen listed in your `CMakeLists.txt`: {{{ catkin_rosjava_setup(publishMavenJavaPublicationToMavenRepository) }}} In particular, the `publishMavenJavaPublicationToMavenRepository` task. This creates the rules that eventually publish your jar into the local workspace's maven repository. === Compiling with Gradle === You could alternatively just compile your subproject alone with gradle (much faster than running catkin_make across your entire workspace): {{{ > source devel/setup.bash > cd src/rosjava_catkin_package_a/my_java_library > ../gradlew publishMavenJavaPublicationToMavenRepository }}} You might like to set `publishMavenJavaPublicationToMavenRepository` as a default task inside `build.gradle` so you can just call `gradlew` without arguments. === Dependencies === Inspecting this tutorial's `build.gradle` illustrates an empty file (ok, just comments). If your classes were to have other rosjava dependencies, you would add them to the dependency closure here. If you would like to make this library available to other projects, then you would need to add to the dependency closure in those projects. If it was a sibling gradle subproject: {{{ # build.gradle dependencies { compile project(':my_java_library') } }}} If it was an different catkin-gradle package altogether: {{{ # build.gradle dependencies { compile 'com.github.rosjava.rosjava_catkin_package_a:my_java_library:[0.1,)' } }}} and to make sure catkin_make can sequence your source builds correctly: {{{ # package.xml rosjava_catkin_package_a rosjava_catkin_package_a }}} ## AUTOGENERATED DO NOT DELETE ## TutorialCategory ## FILL IN THE STACK TUTORIAL CATEGORY HERE