[sleuthkit-users] Java bindings: ClassNotFoundException TskDataException
Brought to you by:
carrier
From: <zah...@gm...> - 2015-09-02 09:32:08
|
Hey everyone, I just started using Tsk. To get a feeling I wanted to try out the sample (Sample.java, see below). I build it with Ant (build.xl, see below). While the build itself is successful I can't get the program to run (java -jar Sample.jar). I am working on a Linux Machine, the JNI libs are in /usr/lib. The file Tsk_DataModel.jar I copied to projectdir/lib. This is the message I get: 'Exception in thread "main" java.lang.NoClassDefFoundError: org/sleuthkit/datamodel/TskDataException at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2625) at java.lang.Class.getMethod0(Class.java:2866) at java.lang.Class.getMethod(Class.java:1676) at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486) Caused by: java.lang.ClassNotFoundException: org.sleuthkit.datamodel.TskDataException So could anyone help me on that? Thanks. Sample.java: package main; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.Image; import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.SleuthkitJNI.CaseDbHandle.AddImageProcess; import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.TskDataException; public class Sample { public static void run(String imagePath) { try { SleuthkitCase sk = SleuthkitCase.newCase(imagePath + ".db"); // initialize the case with an image String timezone = ""; AddImageProcess process = sk.makeAddImageProcess(timezone, true, false); ArrayList<String> paths = new ArrayList<String>(); paths.add(imagePath); try { process.run(paths.toArray(new String[paths.size()])); } catch (TskDataException ex) { Logger.getLogger(Sample.class.getName()).log(Level.SEVERE, null, ex); } process.commit(); // print out all the images found, and their children List<Image> images = sk.getImages(); for (Image image : images) { System.out.println("Found image: " + image.getName()); System.out.println("There are " + image.getChildren().size() + " children."); for (Content content : image.getChildren()) { System.out.println('"' + content.getName() + '"' + " is a child of " + image.getName()); } } // print out all .txt files found List<AbstractFile> files = sk.findAllFilesWhere("name like '%.txt'"); for (AbstractFile file : files) { System.out.println("Found text file: " + file.getName()); } } catch (TskCoreException e) { System.out.println("Exception caught: " + e.getMessage()); Sample.usage(e.getMessage()); } } public static void usage(String error) { System.out.println("Usage: ant -Dimage:{image string} run-sample"); if (error.contains("deleted first")) { System.out.println("A database for the image already exists. Delete it to run this sample again."); } else if (error.contains("unable to open database")) { System.out.println("Image must be encapsulated by double quotes. Ex: ant -Dimage=\"C:\\Users\\You\\image.E01\" run-sample"); } } public static void main(String[] args) { Sample.run(args[0]); } } build.xml: <project name="Sample" basedir="." default="main"> <property name="src.dir" value="src"/> <property name="build.dir" value="build"/> <property name="classes.dir" value="${build.dir}/classes"/> <property name="jar.dir" value="${build.dir}/jar"/> <property name="main-class" value="main.Sample"/> <property name="lib.dir" value="lib"/> <path id="master-classpath"> <fileset dir="${lib.dir}"> <include name="*.jar"/> </fileset> <pathelement path="${build.dir}"/> </path> <target name="clean"> <delete dir="${build.dir}"/> </target> <target name="compile"> <mkdir dir="${classes.dir}"/> <javac includeantruntime="false" destdir="${classes.dir}"> <src path="${src.dir}"/> <classpath refid="master-classpath"/> </javac> </target> <target name="jar" depends="compile"> <mkdir dir="${jar.dir}"/> <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}"> <manifest> <attribute name="Main-Class" value="${main-class}"/> </manifest> </jar> </target> <target name="run" depends="jar"> <java fork="true" classname="${main-class}"> <classpath> <path refid="master-classpath"/> <path location="${jar.dir}/${ant.project.name}.jar"/> </classpath> </java> </target> <target name="clean-build" depends="clean,jar"/> <target name="main" depends="clean,run"/> </project> |