当我尝试执行此代码时: 包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));
}
我明白了:
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
这是我的清单文件:
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
以下是jar文件本身的列表:
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
那么类路径应该是什么,因为我使用的是Netbeans,我认为这是IDE的工作来实际处理这个问题。只有当我将所有内容打包到jar中时才会发生这种情况,当我从IDE运行代码时,一切都按预期工作。
答案 0 :(得分:4)
查看它找不到的类名:
uk/org/infectogenomics/Agent/qa/Quasr
现在看看你的jar文件内容:
uk/org/infectogenomics/agent/qa/Quasr.class
存在套管差异。我的猜测是在某些时候你已经将包名改为小写(应该是IMO),但你是在Windows上(有案例 - 不敏感的文件系统),因此现有的“代理”目录被保留而不是被擦除并替换为“代理”。
如果从头开始重建,可能会将所有内容排序。另一方面,我建议更改包名称以遵循正常的Java命名约定。