[resolved] java.lang.ClassNotFoundException when deploying job in runtime
Hello Team,
I am using log4j in my custom java component. In talend job I have separate tLibraryLoad component to import log4j jar file. Everything works fine as long as I test it in talend studio. But as soon as I export this job and deploy it to runtime I get ClassNotFoundException (below). I export job by right-click > build job > OSGI bundle for ESB. Then I copy jar file into Runtime_ESBSE\container\deploy folder. It deploys fine. But when I invoke service, I get this error.
I checked other posts on the forum that recommend dropping jar file into container/lib/ext - tried that, did not help.
Please advise.
Thank you!
Svetlana
Caused by: java.lang.NoClassDefFoundError: org/apache/log4j/Layout
at local_project.generalinformationservice_0_1.GeneralInformationService.tRESTRequest_1_LoopProcess(GeneralInformationService.java:7910)
at local_project.generalinformationservice_0_1.GeneralInformationService$RestServiceProviderImpl4TalendJob.processRequest(GeneralInformationService.java:1051)
... 28 more
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Layout cannot be found by local_project.GeneralInformationService_0.1.0
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:389)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:352)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:344)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
Hi xldai,
I have tried 6.1.1. It still generates manifest file with log4j line which breaks in runtime. After playing around I confirmed the following: to make it working for all talend versions I have to do two things: 1. remove log4j line from manifest file and 2. have log4j.jar in container/lib/ext folder. I don't mind copying jar file into .../ext folder bud I would like to avoid manual manipulations of osgi bundle. Is there any way to configure built of osgi bundle and somehow exclude unwanted packages?
Thank you!
Svetlana
Hello Svetlana
the usage pattern is - as the project dependency set the Log4J or SLF4J version which is provided by the runtime (I believe in the TESB 5.6.2 it's Log4j 1.2.5 but please check yourself). Use only the simple Logger interface as xldai mentioned
private static final org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(MyClass.class); logger.info("hello!");
The pattern, log level, log file, ... is to be configured in the property file etc/org.ops4j.pax.logging.cfg (so you don't refer the inner classes). This way you be reusing the logging infrastructure already provided. I know you may be limited with the features of the Pax Logging API implementation (e.g. I did not find any way to do any XML configuration supporting the compressed log archives), but for the rest you should be ok with that.
Gabriel