One Star

commons-lang-2.1.jar not loading in Run

I am using commons-lang-2.1.jar in the expression editor. I have an import org.apache.commons.lang.StringUtils; in my Clustering.java file.
I have eventually added a classpath variable to the preferences/Java/Build path/ classpath variables dialog. The job runs fine in the Debug mode, but in Run it says
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils
at routines.Clustering.Match(Clustering.java:320)
at bargaintest.clusteringfinddups.ClusteringFindDups.tFileInputDelimited_1Process(ClusteringFindDups.java:1523)
at bargaintest.clusteringfinddups.ClusteringFindDups.runJobInTOS(ClusteringFindDups.java:1970)
at bargaintest.clusteringfinddups.ClusteringFindDups.main(ClusteringFindDups.java:1871)
I tried to use tLibraryLoad component but that seemed to do nothing in the code and did not produce any improvement, nor write the commons-lang-2.1.jar into the java code.
Strange it works in Debug and not Run.
3 REPLIES
Employee

Re: commons-lang-2.1.jar not loading in Run

Make a right-click on your routines -> Edit Routine Libraries.
This will automatically add your routine libraries to runtime classpath.
Your library will also be exported with your job if needed.
Configuration of preferences/Java/Build path/ classpath variables has strictly no effect.
HTH,
One Star

Re: commons-lang-2.1.jar not loading in Run

This should be added as a sticky of part of the FAQ, especially because the writing of custom code is not well documented in the otherwise excellent user guide.
I sort of tore my hair out before finally finding this post.
One problem in my case was that three commons-lang jar modules are in the lib directory, so I thought all those get loaded. Seems to be wrong...
TOS-All-r47759-V4.0.3\lib\java\commons-lang-1.0.jar
TOS-All-r47759-V4.0.3\lib\java\commons-lang-2.1.jar
TOS-All-r47759-V4.0.3\lib\java\commons-lang-2.4.jar
They do not seem to get loaded.
Another problem of course is that when there is an error it is hard to determine what part of the error log would be best to search for. In this case java.lang.NoClassDefFoundError was not enough had to add: org/apache/commons/lang/StringUtils
One Star

Re: commons-lang-2.1.jar not loading in Run

After deciding that I would report this as a bug the response from mhirt was the following at http://www.talendforge.org/bugs/view.php?id=15740
Hi,
That's really not a bug.
Modules view reference the Available libraries.
When you will export your job, only the really required libraries will be added to your job. Else it would be pretty a quite big export....
The really needed libraries are computed using :
* list of component of your job
* libraries referenced the specific tLibraryLoad component
* routines
If you're using some custom code in a routine, you must reference the library that must be used within the routines properties.
If you're using some tJavaXXX components, you should use the tLibraryLoad component.
Hth,

Thanks and also thanks for the quick response.
BTW, all this should be added to the documentation.
And I think that even in the Studio the libraries should be managed in the preferences in the same area where the classpath, etc. are stored.