Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!

Talend: Resolving class and JAR related issues

No ratings
cancel
Showing results for 
Search instead for 
Did you mean: 
TalendSolutionExpert
Contributor II
Contributor II

Talend: Resolving class and JAR related issues

Last Update:

Jan 22, 2024 9:35:30 PM

Updated By:

Jamie_Gregory

Created date:

Jul 29, 2021 4:52:28 PM

There can be many root causes for JAR file errors and just as many ways to investigate and fix them. This article shows you how to troubleshoot some of the issues related to external, and Talend generated JAR files.

To understand what can lead to JAR file issues, you need to understand how Talend code generation works. Talend builds Java code and compiles that code into classes, then stores them in JAR files. Thus the following error could mean many things, such as:

  • JAR file doesn't exist

  • JAR exists, but it's empty

  • JAR file is missing from the .sh / .bat file; or is present with the wrong name

  • JAR is not in the right format:

    'Could not find or load * class'

    You can unzip JAR files and verify that they contain .class files.

 For more information on building Java code, see Component code generation model, available in the Talend Help Center.
 

Problem types

There are many causes for errors. The following examples help you understand some of the different reasons.

Missing external libraries

It is important to understand how external libraries link to Talend Jobs.

Components

To understand what component requires which JAR file see Installing external modules in the Talend Help Center.

Sometimes a component uses different JARs based on different settings. For example, an Oracle connection uses different drivers for different versions, and using SSL can include a few extra JARs in the build.

Routines

Working with an SDK or API and writing Java code can be done in the Jobs as well, but using a Routine is usually more convenient. You can add dependent JARs in the Routines by clicking Edit Routine Libraries, checking if the JAR exists as a Platform JAR, then select it as shown below:

 minimaljson.gif

 

Understanding the Required check box

Before Talend 7, the Routine editor recognized the JARs from the open Jobs. The Routine was compiled together with the Jobs and their dependencies without validating the generated Java code.

However, in Talend 7, Routines are compiled as standalone entities before any of the Jobs are compiled, requiring the JARs to be present. Selecting the Required check box includes JARs in the final build along with the Routine.

If Required isn't selected, then these are still required for the compilation. However, you can only use the Routine with the Jobs that require the dependent JARs; that is, it is either required by another component or forced using the tLibraryLoad component.

For example, a Job uses an S3 connection. A Routine is created to use a feature from the Amazon SDK. The Routine requires the AWS SDK for compilation, but it’s optional as it is used together with the S3 connection that loads the SDK.

In other words: if the Routine is a standalone solution (that is, it uses an SDK that is not available in Talend), you need to select the Required check box.

Using the tLibraryLoad component

You can use the tLibraryLoad component to override the loaded JARs and their order. The JARs loaded by this component are placed at the beginning of the classpath, so you can use this component to forcefully load a class. However, Talend recommends using this component to add missing JARs and not to modify JAR versions.

Important: Classes are loaded from the JARs in the classpath. If multiple JARs contain the same class, the class is loaded from the JAR appearing first in the classpath.

Possible issues with external libraries

The following error may be due to:

  • JAR files are required to make it fully functioning, but they failed to load

  • Routines don't have the Required check box for the library in dependency, so the build doesn't contain .class files

  • Routines and components require the same JAR but with a different version

Exception: (java.lang.NoClassDefFoundError) org/apache/commons/csv/CSVFormat

 Another class-related error:

Exception in component tFileInputExcel_1 (excel_thmap_test) 
java.lang.IllegalArgumentException: InputStream of class 
    class org.apache.commons.compress.archivers.zip.ZipFile$1 is not implementing InputStreamStatistics. 
   at org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream.

 The exception above tells you that the JAR file loaded successfully, and that it is not implementing Statistics. This means that Java is most likely not looking for this JAR file. In this case, a newer version contains a function that implements Statistics. Mixing multiple versions could lead to such errors.

There are rare cases when the content of a JAR file becomes corrupt inside Nexus or the chosen artifact repository. In this case, you need to fix it manually, as Studio will download it for each build. Each artifact repository is different, but in most cases, you can use the following steps to fix it manually.

  1. Create a backup of the pom.xml file (in some cases, it can contain additional dependencies).

  2. Download the correct JAR file from Maven Central.

  3. Delete the artifact folder (JAR, POM, and other files).

  4. Add a new artifact.

  5. Browse the JAR + POM file.

  6. Studio should automatically download the new JAR file at the next build or execution.

 Possible reasons for this type of corruption include:

  • File is empty

  • JAR is not a valid zip file (each JAR can be opened as a zip)

  • Content doesn't match (MySQL.jar contains Hadoop classes)

  • JAR file is in a compressed zip file (so uncompressing the file results in the right JAR file)

Available JARs

Sometimes it's necessary to understand what JARs are used by a given component. You can use the Modules view to see which component uses which JARs and where a given JAR is used.

For more information about which component requires which JAR file, see Installing external modules, available in the Talend Help Center.

Opening the Modules view

opening modules view.gif

 Using the Modules view

using modules view.gif

Upgrading the JAR version

It's generally a good idea to use the latest version in case multiple versions are present. You can do this by copying and pasting the MVN URI into the Custom MVN URI field.

upgrading jar version.gif

Main class issue

The code Talend generates also results in class files that are packaged into JAR files. The main class JAR file should not be in the lib folder but rather in the folder with the same name as the Job itself.

To display which class is loaded from which JAR, use the following JVM parameter:

-verbose:class

 The following error may be due to:

  • Main Job JAR is not in the right folder (check if it's in a different folder)
  • JAR files generated by Talend should be in the folder named according to the main Jobs
  • JAR file size shouldn't be too small (that is, if it's 2 kb, then it is missing something)
  • Open the .jar file with 7-Zip and verify that it contains the .class files
  • Java is missing or misconfigured.​​​ Inside window/preferences validate the following menus:
    • Java > Installed JREs
    • Talend (Java Intepreter)
Error: Could not find or load main class

 If the JAR file is present and has content, but you are still getting errors: Check the .bat and .sh files, and ensure they include the JAR files in the classpath.

Having extra spaces in the .sh file between the /lib and -cp parameters could also result in such errors, and could be because of multiple things. To help resolve this issue, check the following:

  • In Studio, verify that the Sh script doesn't have extra spaces in the highlighted area.

talend job jvmargs.png 

  • Ensure that the JVMargs are present and loaded by checking the .bat and .sh files. The JVMargs look like this: -Xms256M.

 

Collecting information

If you are still experiencing issues, this section shows you how to collect additional information to share with the Talend Support team.

Enable the Error Logs view

enable error logs view.gif

Window -> Show View -> General/Error logs

Enabling Maven debug logs

enable maven debug logs.gif

 Building the Job

Build the Job, then get the lastGenerated.log file using Project Explorer:

building the job.gif

 Enabling Project Explorer

enabling project explorer.gif

Locating the lastGenerated.log

The file should be under the <PROJECTNAME> _ <JOBNAME> folder.

locating the lastgenerated log.gif

 

Also, collect the Help > Support Logs to see if those contain any errors.

support logs.gif

Labels (2)
Version history
Last update:
‎2024-01-22 09:35 PM
Updated by: