使用控制台时出现 java.lang.NoClassDefFoundError [英] java.lang.NoClassDefFoundError when using console

查看:73
本文介绍了使用控制台时出现 java.lang.NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在通过控制台执行程序时遇到问题.它总是抛出 java.lang.NoClassDefFoundError 但如果我使用 netbeans 运行相同的应用程序,它可以完美运行.我该怎么办?

I have a problem with the execution of programs by console. It always throws java.lang.NoClassDefFoundError but if i run the same application with netbeans it works perfectly.What can i do?

推荐答案

您的类路径设置不同,即当您从控制台运行相同的代码时,NetBeans 中类路径上的 jar 不在类路径上.

Your classpath is set differently i.e. jar(s) on the classpath in NetBeans are not on the classpath when you run the same code from the console.

输出类路径中内容的快速代码片段:

A quick code snippet which outputs what is on your classpath:

ClassLoader cl = ClassLoader.getSystemClassLoader();

URL[] urls = ((URLClassLoader)cl).getURLs();

for(URL url: urls){ System.out.println(url.getFile()); }

在控制台中,使用 -cp 选项添加必要的 jar.

From the console, use the -cp option to add the necessary jars.

这篇关于使用控制台时出现 java.lang.NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆