Java.lang.NoClassDefFoundError: Failed to initialize javax.media.jai.JAI class

I recently started my first program with GeoTools, in which I also used JAI-Java Advanced Imaging 1_1_2_01 with JDK 1_7. It worked fine until I added GeoTiff Jars . I found the following error

Exception in thread "main" java.lang.NoClassDefFoundError: Failed to initialize javax.media.jai.JAI class on org.geotools.gce.geotiff.GeoTiffReader.read (GeoTiffReader.java:607) at com.rgb.PixelExtractor.ext (PixelExtractor.java:55) at com.rgb.RGBSpliter.main (RGBSpliter.java:136)

Code below

public void extract(File f, String name, String date) throws Exception { ParameterValue<OverviewPolicy> policy = AbstractGridFormat.OVERVIEW_POLICY .createValue(); policy.setValue(OverviewPolicy.IGNORE); // this will basically read 4 tiles worth of data at once from the disk... ParameterValue<String> gridsize = AbstractGridFormat.SUGGESTED_TILE_SIZE.createValue(); //gridsize.setValue(512 * 4 + "," + 512); // Setting read type: use JAI ImageRead (true) or ImageReaders read methods (false) ParameterValue<Boolean> useJaiRead = AbstractGridFormat.USE_JAI_IMAGEREAD.createValue(); useJaiRead.setValue(true); //reader.read(new GeneralParameterValue[] { policy, gridsize, useJaiRead }); // The line that throws error GridCoverage2D image = new GeoTiffReader(f).read(new GeneralParameterValue[]{policy, gridsize, useJaiRead}); Rectangle2D bounds2D = image.getEnvelope2D().getBounds2D(); bounds2D.getCenterX(); // calculate zoom level for the image GridGeometry2D geometry = image.getGridGeometry(); BufferedImage img = ImageIO.read(f); // ColorModel colorModel = img.getColorModel( WritableRaster raster = img.getRaster(); int numBands = raster.getNumBands(); int w = img.getWidth(); int h = img.getHeight(); outer: for (int i = 0; i < w; i++) {//width... for (int j = 0; j < h; j++) { double[] latlon = geo(geometry, i, j); double lat = latlon[0]; double lon = latlon[1]; Double s = 0d; String originalBands = ""; for (int k = 0; k < numBands; k++) { double d = raster.getSampleDouble(i, j, k); originalBands += d + ","; s += d; } originalBands = originalBands.substring(0, originalBands.length() - 1); if (s.compareTo(0d) == 0) { continue; } String geoHash = GeohashUtils.encodeLatLon(lat, lon); //here do something with the bands, lat, long, geohash, etc.... } } } private static double[] geo(GridGeometry2D geometry, int x, int y) throws Exception { //int zoomlevel = 1; Envelope2D pixelEnvelop = geometry.gridToWorld(new GridEnvelope2D(x, y, 1, 1)); // pixelEnvelop.getCoordinateReferenceSystem().getName().getCodeSpace(); return new double[]{pixelEnvelop.getCenterY(), pixelEnvelop.getCenterX()}; } } 

Jdk jars

Jdk images jar

Other banks

Part1

part2

I also added a classpath variable for GeoTools cans

classpath

Edit:

My jai works without GeoTools integration, but when I add gt-geotiff-14.4.jar , it tries to add JAI-core-1.1.3.jar , which conflicts with jai-core.jar in my JDK 1.7. So I uninstalled JAI-core-1.1.3.jar and its associated banks, but still it gives me the same error.

+5
source share
3 answers

Finally, it worked when I deleted the Geotiff files jai-core-1.1.3.jar , jai-codec-1.1.3.jar and jai-imageio-1.1.jar and added a new class for jai-ext class files. I just copied from github and added my project to src. gt-utility was one that was missing. Banks are also controversial.

+3
source

You should add jai-core.jar to your classpath

+2
source

Follow the instructions for Geotools setup instructions that speak for JAI

Java Advanced Imaging Java Advanced Imaging is an image processing library that allows you to create chains of operations for processing rasters similar to functional programming.

Literature:

http://java.net/projects/jai-core Download this version of JAI

Java Advanced Imaging API 1.1.3 At the time of writing Oracle porting Java projects - try the following:

http://download.java.net/media/jai/builds/release/1_1_3/ http://download.java.net/media/jai/builds/release/1_1_3/INSTALL.html Download the JAI for your JDK by clicking link to your platform:

Example: jai-1_1_3-lib-windows-i586-jdk.exe

Use the one-click installer to install JAI in your JDK

Download the JAI for your JRE by clicking on the link for your platform:

Example: jai-1_1_3-lib-windows-i586-jre.exe

Use the one-click installer to install JAI in the JRE

(If you are working on linux, you will of course need to choose the appropriate download)

0
source

All Articles