Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Jan 22, 2024 9:35:30 PM
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.
There are many causes for errors. The following examples help you understand some of the different reasons.
It is important to understand how external libraries link to Talend Jobs.
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.
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:
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.
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.
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.
Create a backup of the pom.xml file (in some cases, it can contain additional dependencies).
Download the correct JAR file from Maven Central.
Delete the artifact folder (JAR, POM, and other files).
Add a new artifact.
Browse the JAR + POM file.
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)
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.
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.
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:
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:
Ensure that the JVMargs are present and loaded by checking the .bat and .sh files. The JVMargs look like this: -Xms256M.
If you are still experiencing issues, this section shows you how to collect additional information to share with the Talend Support team.
Window -> Show View -> General/Error logs
Build the Job, then get the lastGenerated.log file using Project Explorer:
The file should be under the <PROJECTNAME> _ <JOBNAME> folder.
Also, collect the Help > Support Logs to see if those contain any errors.