<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: NoClassDefFoundError when running routine using an external library in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/NoClassDefFoundError-when-running-routine-using-an-external/m-p/2372891#M135679</link>
    <description>Hello&amp;nbsp; 
&lt;BR /&gt;The code should work both on tMap and tJava component if the library is loaded correctly. I have downloaded the external library commons-lang3-3.1.jar from internet and tested your code, it works on tJava. I am using version 6.1.1. Which version are you using?&amp;nbsp; 
&lt;BR /&gt; 
&lt;BR /&gt;Regards 
&lt;BR /&gt;Shong</description>
    <pubDate>Wed, 22 Jun 2016 03:42:01 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2016-06-22T03:42:01Z</dc:date>
    <item>
      <title>NoClassDefFoundError when running routine using an external library</title>
      <link>https://community.qlik.com/t5/Talend-Studio/NoClassDefFoundError-when-running-routine-using-an-external/m-p/2372887#M135675</link>
      <description>&lt;P&gt;I've been experimenting with all the different ways you can call a method from an external java library from within a Talend job.&amp;nbsp; I was able to create a Routine that calls a method from the Apache Commons Lang library.&amp;nbsp; As a test, I wanted to use the StringUtils.capitalize method to capitalize Strings in a variety of use cases.&amp;nbsp; I figured a Routine would be most appropriate.&lt;BR /&gt;&lt;BR /&gt;I added the Apache Commons Lang jar as a new library in the User Libraries screen.&amp;nbsp; Then, I created a new Routine called ApacheStringUtils.&amp;nbsp; Within it, I created a method called capitalize which called the StringUtils.capitalize method in the Apache Commons Lang library.&amp;nbsp; The Routine looks like this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt; 
&lt;PRE&gt;package routines;&lt;BR /&gt;&lt;BR /&gt;import org.apache.commons.lang3.StringUtils;&lt;BR /&gt;&lt;BR /&gt;public class ApacheStringUtils {&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /**&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * capitalize: returns a String with a capitalized first character&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * {talendTypes} String&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * {Category} User Defined&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * {param} string str: The string needing to be capitalized.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static String capitalize(String str) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; return StringUtils.capitalize(str);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /**&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * uncapitalize: returns a String with an uncapitalized first character&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * {talendTypes} String&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * {Category} User Defined&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * {param} string str: The string needing to be uncapitalized.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static String uncapitalize(String str) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; return StringUtils.uncapitalize(str);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;}&lt;/PRE&gt; 
&lt;P&gt;&lt;BR /&gt;This Routine showed no errors.&lt;BR /&gt;&lt;BR /&gt;To test, I successfully ran the Routine in a tJava component with the following code:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt; 
&lt;PRE&gt;&amp;nbsp; System.out.println(ApacheStringUtils.capitalize("word"));&lt;/PRE&gt; 
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;This job printed out "Word" as expected.&lt;BR /&gt;&lt;BR /&gt;However, when I tried to use this same routine in a tMap expression, it failed due to the following NoClassDefFoundError exception:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt; 
&lt;PRE&gt;Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; at routines.ApacheStringUtils.uncapitalize(ApacheStringUtils.java:33)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; at test_talend.manipulatecsvdatatest_0_1.ManipulateCSVDataTest.tFileInputDelimited_1Process(ManipulateCSVDataTest.java:2242)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; at test_talend.manipulatecsvdatatest_0_1.ManipulateCSVDataTest.runJobInTOS(ManipulateCSVDataTest.java:2846)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; at test_talend.manipulatecsvdatatest_0_1.ManipulateCSVDataTest.main(ManipulateCSVDataTest.java:2680)&lt;BR /&gt;Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; at java.net.URLClassLoader.findClass(Unknown Source)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; at java.lang.ClassLoader.loadClass(Unknown Source)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; at java.lang.ClassLoader.loadClass(Unknown Source)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ... 4 more&lt;/PRE&gt; 
&lt;P&gt;&lt;BR /&gt;This didn't make much sense to me, as it was running successfully in a tJava component.&amp;nbsp; Why not here?&amp;nbsp; When I pressed Ctrl+Space when filling in my expression, I was even able to see my ApacheStringUtils methods.&amp;nbsp; In fact, the methods from the imported library's StringUtils class showed up as well.&amp;nbsp; I tried using those directly, but received an error that those methods were "undefined for type StringUtils."&lt;BR /&gt;&lt;BR /&gt;So, my question is: Why can I access an imported library via a routine in a tJava component but not a tMap expression?&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2016 18:55:51 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/NoClassDefFoundError-when-running-routine-using-an-external/m-p/2372887#M135675</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-06-07T18:55:51Z</dc:date>
    </item>
    <item>
      <title>Re: NoClassDefFoundError when running routine using an external library</title>
      <link>https://community.qlik.com/t5/Talend-Studio/NoClassDefFoundError-when-running-routine-using-an-external/m-p/2372888#M135676</link>
      <description>Hello 
&lt;BR /&gt; 
&lt;BLOCKQUOTE&gt; 
 &lt;FONT size="2"&gt;&lt;FONT face="Verdana," helvetica=""&gt;I added the Apache Commons Lang jar as a new library in the User Libraries screen.&amp;nbsp; Then, I created a new Routine called ApacheStringUtils&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;/BLOCKQUOTE&gt; 
&lt;BR /&gt;I don't understand where do you put the user library, however, please follows the steps to add external libraries: 
&lt;BR /&gt;create your custom routine first, and then right click on it and select 'Edit Routine Libraries' item to add your user libraries. 
&lt;BR /&gt; 
&lt;BR /&gt;Regards 
&lt;BR /&gt;Shong</description>
      <pubDate>Mon, 20 Jun 2016 08:36:51 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/NoClassDefFoundError-when-running-routine-using-an-external/m-p/2372888#M135676</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-06-20T08:36:51Z</dc:date>
    </item>
    <item>
      <title>Re: NoClassDefFoundError when running routine using an external library</title>
      <link>https://community.qlik.com/t5/Talend-Studio/NoClassDefFoundError-when-running-routine-using-an-external/m-p/2372889#M135677</link>
      <description>Well first, I had added the Apache Commons Lang jar as a library under Preferences -&amp;gt; Java -&amp;gt; Build Path -&amp;gt; User Libraries.&amp;nbsp; After I realized that didn't work, I did exactly what you had suggested.&amp;nbsp; I right-clicked on the routine I had created, clicked "Edit Routine Libraries," added the Commons Lang jar, and clicked Finish.&amp;nbsp; 
&lt;BR /&gt; 
&lt;BR /&gt;I tried running the job once more and received the same NoClassDefFoundError as before.&amp;nbsp; 
&lt;BR /&gt; 
&lt;BR /&gt;I'd like to point out once more that the capitalize method in the routine works fine when called from a tJava component.&amp;nbsp; When I try to use it in a tMap component, however, I get the NoClassDefFoundError exception.&amp;nbsp; Any other ideas on what might be wrong?</description>
      <pubDate>Mon, 20 Jun 2016 18:50:36 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/NoClassDefFoundError-when-running-routine-using-an-external/m-p/2372889#M135677</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-06-20T18:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: NoClassDefFoundError when running routine using an external library</title>
      <link>https://community.qlik.com/t5/Talend-Studio/NoClassDefFoundError-when-running-routine-using-an-external/m-p/2372890#M135678</link>
      <description>While I wouldn't call this approach a 
&lt;B&gt;resolution&lt;/B&gt;, I found that I could get my Routine to run within a tMap component by including a tLibraryLoad component to load the Apache Commons library at runtime. 
&lt;BR /&gt; 
&lt;BR /&gt;However, I still do 
&lt;B&gt;not &lt;/B&gt;need to do this when calling my routine from a tJava component.&amp;nbsp; I don't know why this is the case - I thought defining a routine and specifying the library required by the Routine meant that I wouldn't need to load the required library in each job the Routine is called from.&amp;nbsp; It's definitely inconvenient for others who wish to use my Routine since they likely won't be aware of the required library when using it.&amp;nbsp; Their job will fail and they will need to look at the code to understand which library it needs.&amp;nbsp; This would especially be a hassle for non-developers who wish to use a custom Routine but don't know much about Java and library dependencies! 
&lt;BR /&gt; 
&lt;BR /&gt;I feel as though I'm not doing something correctly, so I will leave as unresolved until I receive an answer.</description>
      <pubDate>Tue, 21 Jun 2016 19:43:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/NoClassDefFoundError-when-running-routine-using-an-external/m-p/2372890#M135678</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-06-21T19:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: NoClassDefFoundError when running routine using an external library</title>
      <link>https://community.qlik.com/t5/Talend-Studio/NoClassDefFoundError-when-running-routine-using-an-external/m-p/2372891#M135679</link>
      <description>Hello&amp;nbsp; 
&lt;BR /&gt;The code should work both on tMap and tJava component if the library is loaded correctly. I have downloaded the external library commons-lang3-3.1.jar from internet and tested your code, it works on tJava. I am using version 6.1.1. Which version are you using?&amp;nbsp; 
&lt;BR /&gt; 
&lt;BR /&gt;Regards 
&lt;BR /&gt;Shong</description>
      <pubDate>Wed, 22 Jun 2016 03:42:01 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/NoClassDefFoundError-when-running-routine-using-an-external/m-p/2372891#M135679</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-06-22T03:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: NoClassDefFoundError when running routine using an external library</title>
      <link>https://community.qlik.com/t5/Talend-Studio/NoClassDefFoundError-when-running-routine-using-an-external/m-p/2372892#M135680</link>
      <description>The code only works with the tJava component.&amp;nbsp; I can't get it to work in the tMap component unless I add in an additional tLibraryLoad component to load the Apache library again. 
&lt;BR /&gt; 
&lt;BR /&gt;I am also using 6.1.1.&amp;nbsp; Could you share with me what steps you took to import the Apache commons library such that it will work in the tMap component?</description>
      <pubDate>Wed, 22 Jun 2016 13:57:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/NoClassDefFoundError-when-running-routine-using-an-external/m-p/2372892#M135680</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-06-22T13:57:25Z</dc:date>
    </item>
  </channel>
</rss>

