在Linux下用JDK编译一个java文件报的错。
多谢了!
多谢了!
解决方案 »
- 关于一种泛型方法的作用
- 新手请教如何把CLASS文件生成能用的JAR,JAD格式
- 问下,html难不难学?
- JAVA交流区 `~希望大家参与!
- 求:scjp考试大纲中的一条
- TABLE问题
- ???求助高手,关于序列化的问题,必有重谢:)
- PrintTest.java的目录是C:\javacode\com\szallcom\tools;C:\javacode\wf\common目录有SystemProperties.class;编译要求引入wf.common.S
- 放寒假了,终于有时间做自己的开发。先放点分!~~
- VISUAL J++6 好用吗?
- 想问一下,什么时候需要用到内部类?
- 一个通用的权限管理系统,源代码及UML完整设计方案,很快就出来,哪个想要的话,请与我联系!
环境变量都设好了的。
一般出现NoClassDefFoundError错误都不是程序本身的问题
以下是源代码,各位帮忙看看。
public class Ldif2Ldap {
public static void main( String[] args ) { if (args.length != 4) {
usage();
} int changeType, version = 1;
int ldapPort = LDAPConnection.DEFAULT_PORT;
int ldapVersion = LDAPConnection.LDAP_V3;
String fileName = args[0];
String ldapHost = args[1];
String loginDN = args[2];
String password = args[3];
LDIFReader reader = null;
LDAPEntry entry;
LDAPMessage msg, retMsg;
Ldif2Ldap readerTest = new Ldif2Ldap();
LDAPConnection lc = new LDAPConnection(); try {
FileInputStream fis = new FileInputStream( fileName);
reader = new LDIFReader(fis, version);
}
catch (Exception e) {
System.err.println("\nFailed to read LDIF file " + fileName +
", " + e.toString());
System.exit (1);
} try {
// connect to the server
lc.connect( ldapHost, ldapPort );
// bind to the server
lc.bind( ldapVersion, loginDN, password ); if (!reader.isRequest()) {
System.out.println("\nLDIF content file\n"); while ( (msg = reader.readMessage()) != null) {
entry = ((LDAPSearchResult)msg).getEntry();
System.out.println("\nEntry DN:" + entry.getDN());
readerTest.showAttributes(entry);
}
}
else {
System.out.println("\nLDIF change file\n"); while ( (msg = reader.readMessage()) != null) {
if (msg instanceof LDAPAddRequest) {
System.out.println("Adding entry...");
}
else if (msg instanceof LDAPDeleteRequest) {
System.out.println("Deleting entry...");
}
else if (msg instanceof LDAPModifyDNRequest) {
System.out.println("Modifying entry's RDN...");
}
else if (msg instanceof LDAPModifyRequest) {
System.out.println("Modifying entry's attribute(s)...");
} LDAPMessageQueue queue = lc.sendRequest(msg, null, null);
if ((retMsg = queue.getResponse()) != null) {
LDAPResponse response = (LDAPResponse)retMsg;
int status = response.getResultCode(); // the return code is LDAP success
if ( status == LDAPException.SUCCESS ) {
System.out.println("Directory information has been"
+ " modified.");
}
// the reutrn code is referral exception
else if ( status == LDAPException.REFERRAL ) {
String urls[]=((LDAPResponse)retMsg).getReferrals();
System.out.println("Referrals:");
for ( int i = 0; i < urls.length; i++ )
System.out.println(" " + urls[i]);
}
// general error
else {
System.out.println( response.getErrorMessage());
}
}
System.out.println();
}
}
}
catch ( IOException ioe ) {
System.out.println("Error: " + ioe.toString() );
System.exit( 1 );
}
catch ( LDAPException le ) {
System.out.println("Error: " + le.toString() );
System.exit( 1 );
} System.exit (0);
} public static void usage() {
System.err.println("Usage: java Lidf2Ldap <in file name> "
+ "<host name> <login dn> <password>");
System.err.println("Example: java Lidf2Ldap inFile Acme.com "
+ " \"cn=admin,o=Acme\" secret");
System.exit(1);
} public void showAttributes(LDAPEntry entry) { String value;
LDAPAttributeSet as = null;
LDAPAttribute[] attrs = null;
LDAPAttribute attr = null;
Iterator allAttrs;
Enumeration allAttrValues; as = entry.getAttributeSet();
allAttrs = as.iterator();
System.out.println(" Attributes:");
while(allAttrs.hasNext()) {
attr = (LDAPAttribute)allAttrs.next();
System.out.println(" " + attr.getName());
allAttrValues = attr.getStringValues();
if( allAttrValues != null) {
while(allAttrValues.hasMoreElements()) {
value = (String) allAttrValues.nextElement();
System.out.println(" " + value);
}
}
}
}
}
环境变量什么的都绝对没问题!
Exception in thread "main" java.lang.NoClassDefFoundError:Ldif2Ldap
java_home=D:\j2sdk1.4.1_01运行demo下的程序没问题,但很简单的程序都会运行报错,
Exception in thread "main" java.lang.NoClassDefFoundError: test/class怎么搞得???????
2.是否使用了包的概念!如果使用了包要将包所在的目录设为classpath,运行的时候要写上包的路径。例如 java mypackage.com.cn.myjava
他在Linux下用-cp设了环境变量,是不是用-cp设环境变量不行啊?
以win2000Professional为例,环境配置:假设前提:你的jdk1.4正确安装在C盘的根目录下,
正确配置:"我的电脑"-->"属性"-->"高级"-->"环境变量"-->"系统变量"-->如果没有,则进行新建:变量名:Path 变量值:C:\jdk1.4\bin
变量名:ClassPath 变量值:.;C:\jdk1.4\lib\dt.jar;C;\jdk1.4\lib\tools.jar(注意符号.)
再创建一个"用户变量" 变量名:JAVA_HOME 变量值:C:\jdk1.4
这样一来,如果程序正确,在任何地方进行编译,运行都没有问题
c:\java
ft,还是环境变量的问题!
多谢各位了!