LordDoskias
LordDoskias

Reputation: 3191

Problem loading files from jar (classpath problem)

When I try to execute this code: package uk.org.infectogenomics.agent;

import uk.org.infectogenomics.Agent.qa.Quasr;

public static void main(String[] args) {
//ommited some code
Runnable step = new Quasr(wf.getStepByPos(1));
}

I get:

Exception in thread "main" java.lang.NoClassDefFoundError: uk/org/infectogenomic
s/Agent/qa/Quasr
at uk.org.infectogenomics.agent.Agent.main(Agent.java:55)
Caused by: java.lang.ClassNotFoundException: uk.org.infectogenomics.Agent.qa.Quasr
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 1 more

Here is my manifest file:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.6.0_25-b06 (Sun Microsystems Inc.)
Class-Path: lib/mysql-connector-java-5.1.17-bin.jar lib/aws-java-sdk-1.2.6.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: uk.org.infectogenomics.agent.Agent

And here is the listing of the jar file itself:

META-INF/
META-INF/MANIFEST.MF
uk/
uk/org/
uk/org/infectogenomics/
uk/org/infectogenomics/agent/
uk/org/infectogenomics/agent/Assembly/
uk/org/infectogenomics/agent/hostEl/
uk/org/infectogenomics/agent/qa/
uk/org/infectogenomics/agent/taxonomy/
uk/org/infectogenomics/agent/Agent.class
uk/org/infectogenomics/agent/Assembly/Newbler.class
uk/org/infectogenomics/agent/Assembly/Velvet.class
uk/org/infectogenomics/agent/DBAccessor.class
uk/org/infectogenomics/agent/DateUtils.class
uk/org/infectogenomics/agent/Status$1.class
uk/org/infectogenomics/agent/Status$2.class
uk/org/infectogenomics/agent/Status$3.class
uk/org/infectogenomics/agent/Status$4.class
uk/org/infectogenomics/agent/Status.class
uk/org/infectogenomics/agent/Workflow.class
uk/org/infectogenomics/agent/WorkflowStep.class
uk/org/infectogenomics/agent/agent.properties
uk/org/infectogenomics/agent/hostEl/Fastq2FQone.class
uk/org/infectogenomics/agent/hostEl/RepeatMasker.class
uk/org/infectogenomics/agent/hostEl/SplitFiles.class
uk/org/infectogenomics/agent/qa/Quasr.class
uk/org/infectogenomics/agent/taxonomy/Phymbl.class

So what should the classpath be and since I'm using Netbeans I would assume this is the job of the IDE to actually take care of this. This happens only when I package everything inside a jar, when I run the code from the IDE everything works as expected.

Upvotes: 1

Views: 492

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1503290

Look at the class name it can't find:

uk/org/infectogenomics/Agent/qa/Quasr

Now look at your jar file contents:

uk/org/infectogenomics/agent/qa/Quasr.class

There's a casing difference. My guess is that at some point you've switched over the package name from lowercase (which it should be, IMO) but that you're on Windows (with case-insensitive file system), so the existing "agent" directory was preserved rather than it being wiped and replaced with "Agent".

If you rebuild from scratch, it may well sort everything out. On the other hand, I'd suggest changing the package name to follow the normal Java naming conventions.

Upvotes: 4

Related Questions