I am trying to extract the latitude and longitude from picture files in my java app. I am using intellij for my IDE. I found this library that looks perfect: https://search.maven.org/artifact/com.drewnoakes/metadata-extractor/2.14.0/jar I tried the sample code found at https://github.com/drewnoakes/metadata-extractor/blob/master/Samples/com/drew/metadata/SampleUsage.java
I copied the jar to my project directory and then added it as a directory. I copied and pasted the sample code to a class.
I immediately got errors that the class "Metadata" was not recognized so I added an import line for com.drew.metadata.* and that got rid of those errors.
Now when I try to run the code I get a series of errors of NoClassDefFoundError and am stuck.
Code up to the last line that is throwing the errors:
import com.drew.imaging.ImageMetadataReader;
import com.drew.imaging.ImageProcessingException;
import com.drew.imaging.jpeg.JpegMetadataReader;
import com.drew.imaging.jpeg.JpegProcessingException;
import com.drew.imaging.jpeg.JpegSegmentMetadataReader;
import com.drew.metadata.exif.ExifReader;
import com.drew.metadata.iptc.IptcReader;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
// fran added this one
import com.drew.metadata.*;
public class ExtractLatLng {
public static void extract()
{
String fileAndPath = "C:/Users/Franc/Documents/$$Fran/misc/_online Ed/Picture Renaming/PhotoRenaming0903/IMG_5408.jpg";
File file = new File(fileAndPath);
// There are multiple ways to get a Metadata object for a file
//
// SCENARIO 1: UNKNOWN FILE TYPE
//
// This is the most generic approach. It will transparently determine the file type and invoke the appropriate
// readers. In most cases, this is the most appropriate usage. This will handle JPEG, TIFF, GIF, BMP and RAW
// (CRW/CR2/NEF/RW2/ORF) files and extract whatever metadata is available and understood.
//
try {
Metadata metadata = ImageMetadataReader.readMetadata(file);
Errors:
Exception in thread "main" java.lang.NoClassDefFoundError: com/adobe/internal/xmp/XMPException
at com.drew.imaging.jpeg.JpegMetadataReader.<clinit>(JpegMetadataReader.java:57)
at com.drew.imaging.ImageMetadataReader.readMetadata(ImageMetadataReader.java:146)
at com.drew.imaging.ImageMetadataReader.readMetadata(ImageMetadataReader.java:124)
at com.drew.imaging.ImageMetadataReader.readMetadata(ImageMetadataReader.java:204)
at PR0903.ExtractLatLng.extract(ExtractLatLng.java:35)
at PR0903.Main.main(Main.java:6)
P.S. I am a total newbie. Any help appreciated including better ways/places to ask this question.
I sorted it out. Apparently I needed to include and xmpcore library as well that was not available or included in the metadata-extractor download site. I searched around and found one to download. Included it as a library in my project and it works now.