How can I use Sun's JAI-ImageIO with an Eclipse BIRT plugin? - eclipse

I'm trying to write an extension (plug-in) for Eclipse BIRT reporting. It involves extracting images from a file according to database entries and displaying them.
I am using Sun's JAI-ImageIO to access TIFF file data and convert to PNG for display within the report. My code complies, but throws a NoClassDefFound runtime exception:
SEVERE: Error happened while running the report.
java.lang.NoClassDefFoundError: javax/media/jai/PlanarImage
at org.eclipse.birt.sample.reportitem.rotatedlabel.util.GraphicsUtil.createDocImage
(GraphicsUtil.java:66)
at org.eclipse.birt.sample.reportitem.rotatedlabel.RotatedLabelPresentationImpl.onRowSets
(RotatedLabelPresentationImpl.java:136)
at org.eclipse.birt.report.engine.extension.ReportItemPresentationBase.onRowSets
(ReportItemPresentationBase.java:218)
at org.eclipse.birt.report.engine.presentation.LocalizedContentVisitor.
processExtendedContent(LocalizedContentVisitor.java:966)
...
I am using the PlanarImage.getAsBufferedImage() method, so it should convert to a more standard image object. I have placed the JAI jar files in my JRE and tested the same basic code outside of the Eclipse plugin environment -- that works fine. It appears to be a CLASSPATH problem, but I've verified that all JREs on my system contain the necessary jar and DLL files in the appropriate places.
For a new JDBC driver, you must place the jar(s) in a special sub-directory of plugins -- is there a special place to put other third-party jars so BIRT can use them?

This has been solved in Eclipse extension for opening TIFF type 4 images. Basically you just need to make a subdirectory and place all the JARs and DLLs in it, add the jars to your classpath and add the DLLs to the "plugin dependencies" under "required native libraries".

Related

NoClassDefFound error for com/aspose/pdf/BaseParagraph with aspose pdf 23.1 jdk17 jar in Eclipse

I am trying to work with aspose PDF jar and I am not able to get past the NoClassDefFound error for aspose pdf jar. I am using aspose imaging as well as aspose words jar. Both these do not have these, but only aspose PDF does.
Compilation is successful, but on run time I hit this issue.
I am using eclipse IDE
Any help is highly appreciated as I am running out of options to solve this issue.
**Steps tried : **
Switched workspace
Deleted the entire project
Made sure there is only one class with that name (essentially only one jar)
Classpath entries are fine in eclipse. Buildpath->libraries->add external jars. also order and export is selected.

POI XSSF : javax.xml.stream.FactoryConfigurationError: Provider com.bea.xml.stream.EventFactory not found - Error

I'm having this problem in a RCP Aplication.
A little Introduccion.
My App is build with Eclispe Indigo 32 bits.
I have two projects, one is mainly a library container, and the other project is the main application, and it have a relation to the Library Project, all in one Elipse Workspace.
A few year ago, I was reading xls files, but now I need to read and write xlsx, and xlsm files.
So I downloaded all POI binary files (poi-bin-3.16-20170419).
I managed to add jar files in library Project, so the source filesgive me NO errors.
But when I run the application I get this error:
javax.xml.stream.FactoryConfigurationError: Provider com.bea.xml.stream.EventFactory not found
I try to reorder jar files in "Java Build Path"-> "Order and Export", but the error is the same.
I'll add some screen captures.
Here I try to put Stax-api-xx.jar first, because javax.xml.stream.FactoryFinder is in two libs, jre_1.6 and stax-api !
Where is the error ?
A sneak peak of my workspace:
Best regards
Delete the javax/xml folder from local repository and try building the project again.
This will solve the issue in some cases.

Exporting an Eclipse plugin with a dependency on an external jar

Just recently started using Eclipse and ran into an issue with exporting the plugin I'm working on. I tried to search but so far no luck - but if the answer is already here I'd be grateful if someone can point me to it.
I'm writing a n OSGi/Equinox plugin with Eclipse. The plugin is for a 3rd party system, which allows extensions: basically all jars placed in the application's plugin folder are automatically loaded into the application at startup. I have managed to put together my plugin, it's loading fine and it works.
The issue is that I rely on another plugin which is placed beside mine in the plugins folder. For obvious reasons I do not want to package that plugin into my plugin jar file. I have tried to add the dependency as an external archive, but this breaks the export: when I try to export my plugin project ant complains about missing dependencies and types. (If I actually include the other jar file in my plugin everything works, but obviously this is less then ideal.)
So: how do I set up my plugin project dependency, that it's a) an external dependency and b) doesn't need to be specified with a path or a variable - i.e. how do I tell my exporter to "don't worry, it will be there right beside you"?
Edit: Apparently there's an important detail I didn't mention. The external jar file I depend on is not an OSGi plugin, just a regular jar file with some classes in it. To the 3rd party system it seems all the same (all are under the plugins folder, all are loaded into the application), but for Eclipse the distinction seems important.
If you reference the other plug-in as a dependency in your plug-in's MANIFEST.MF the export should work without errors. The plug-in should be listed in the Require-Bundle list in the MANIFEST.MF.
You can do this in the MANIFEST.MF editor by adding to the 'Required Plug-ins' list on the 'Dependencies' tab of the editor.
Note: When referencing other plug-ins you must always use this method. Do not try adding the plug-in jar to the Java build path or anything like that.
If the jar you want to use is not an Eclipse plug-in you must should include it as part of the plug-in and list the jar in the Bundle-Classpath in the MANIFEST.MF. If you cannot do this you can reference an external jar in the Bundle-Classpath using something like:
Bundle-Classpath: .,external:$LIB_LOCATION$/lib.jar
. is the normal entry in for the plug-in code. external:$LIB_LOCATION$/lib.jar looks for lib.jar in a location defined by the environment variable LIB_LOCATION. This method can be difficult to get right.
In the end the solution to my specific problem was to add the external jar file as an Extra Classpath Entry on the build properties tab (this translated to a "jars.extra.classpath = .jar" entry in the build.properties file). I have also added the jar file to the project itself - after adding the extra class path entry that got changed into an external dependency automatically.
With these two changes I was able to successfully export my plugin, which didn't contain the external jar file, but was able to reference it when loaded into the 3rd party system.

Jasper reports font error

I am using Jasper Reports 5.2.0 and Spring MVC with Maven.
I have done reports using JasperViewer, but suddenly I am getting this error that can't be resolved:
net.sf.jasperreports.engine.util.JRFontNotFoundException: Font '
net/sf/jasperreports/fonts/pictonic/pictonic.ttf
net/sf/jasperreports/fonts/pictonic/pictonic.svg
net/sf/jasperreports/fonts/pictonic/pictonic.eot
net/sf/jasperreports/fonts/pictonic/pictonic.woff
' is not available to the JVM. See the Javadoc for more details.
Delete the jar extra placed jars in your lib folder it works properly
or use same version jar file in maven dependency and webroot ->lib folder or in class path
For me, in one instance, the problem was with the jasperreports version as I had more that one jasperreports jar in my classpath.
My reports were compiled with jasperreports-5.6.0 and in my classpath jasperreports-4.1.1.jar was also included and accidentally jasperreports-4.1.1.jar was "up" in the Build class path order.
Actually, my eclipse project had jasperreports-5.6.0 as a library jar and this project had another project as "Required projects in the build path" that contained the old version of jasperreports.
I moved the jasperreports-5.6.0 to "Up in the build classpath order" than the old version, and the problem got resolved.
Again, later I removed the project dependency and got the problem resolved as well.
So check, whether you have more than one jasperreports library anyhow; if so, remove the unnecessary duplicate jar.
The Problem is one of the fonts you used in Jasper Reports not installed in the system. The solution is to install all missing fonts. Another alternative is to use only the fonts "Serif" and "San-Serif" which eliminates the need of installing fonts seperately and would even work when the code is moved accross different servers.

How to add JAR libraries to WAR project without facing java.lang.ClassNotFoundException? Classpath vs Build Path vs /WEB-INF/lib

How should I add JAR libraries to a WAR project in Eclipse without facing java.lang.ClassNotFoundException or java.lang.NoClassDefFoundError?
The CLASSPATH environment variable does not seem to work. In some cases we add JAR files to the Build Path property of Eclipse project to make the code compile. We sometimes need to put JAR files inside /WEB-INF/lib folder of the Java EE web application to make the code to run on classes inside that JAR.
I do not exactly understand why CLASSPATH does not work and in which cases we should add JARs to Build Path and when exactly those JARs should be placed in /WEB-INF/lib.
The CLASSPATH environment variable is only used by the java.exe command and even then only when the command is invoked without any of the -cp, -classpath, -jar arguments. The CLASSPATH environment variable is ignored by IDEs like Eclipse, Netbeans and IDEA. See also java.lang.ClassNotFoundException in spite of using CLASSPATH environment variable.
The Build Path is only for libraries which are required to get the project's code to compile. Manually placing JAR in /WEB-INF/lib, or setting the Deployment Assembly, or letting an external build system like Maven place the <dependency> as JAR in /WEB-INF/lib of produced WAR during the build, is only for libraries which are required to get the code to deploy and run on the target environment too. Do note that you're not supposed to create subfolders in /WEB-INF/lib. The JARs have to be placed in the root.
Some libraries are already provided by the target JEE server or servletcontainer, such as JSP, Servlet, EL, etc. So you do not need put JARs of those libraries in /WEB-INF/lib. Moreover, it would only cause classloading trouble. It's sufficient to (indirectly) specify them in Build Path only. In Eclipse, you normally do that by setting the Targeted Runtime accordingly. It will automatically end up in Build Path. You do not need to manually add them to Build Path. See also How do I import the javax.servlet / jakarta.servlet API in my Eclipse project?
Other libraries, usually 3rd party ones like Apache Commons, JDBC drivers and JEE libraries which are not provided by the target servletcontainer (e.g. Tomcat doesn't support many JEE libraries out the box such as JSF, JSTL, CDI, JPA, EJB, etc), need to end up in /WEB-INF/lib. You can just copy and paste the physical JAR files in there. You do not necessarily need to specify it in Build Path. Only perhaps when you already have it as User Library, but you should then use Deployment assembly setting for this instead. See also ClassNotFoundException when using User Libraries in Eclipse build path.
In case you're using Maven, then you need to make absolutely sure that you mark libraries as <scope>provided</scope> if those are already provided by the target runtime, such as JEE, Servlet, EL, etc in case you deploy to WildFly, TomEE, etc. This way they won't end up in /WEB-INF/lib of produced WAR (and potentially cause conflicts with server-bundled libraries), but they will end up in Eclipse's Build Path (and get the project's code to compile). See also How to properly install and configure JSF libraries via Maven?
Those JARs in the build path are referenced for the build (compile) process only. If you export your Web Application they are not included in the final WAR (give it a try).
If you need the JARs at runtime you must place them in WEB-INF/lib or the server classpath. Placing your JARs in the server classpath does only make sense if several WARs share a common code base and have the need to access shared objects (e.g. a Singleton).
If you are using Maven:
Open the project properties, and under Deployment Assembly click Add...
Then select Java Build Path Entries and select Maven Dependencies
Resolved by setting permissions.
Had related issue using PySpark and Oracle jdbc. The error does not state that the file cannot be accessed, just that the class cannot be loaded.
So if anyone still struggles, check the permissions. Some might find it obvious tho'.
I want to give the answer for the folowing link question ClassNotFoundException oracle.jdbc.driver.OracleDriver only in servlet, using Eclipse
Ans: In Myeclipse go to Server-->left click on Myeclipse Tomcat7-->Configure Server Connector-->(Expand)Myeclipse Tomcat7--> Paths-->Prepend to classpath-->Add jar (add oracle14 jar)-->ok