如何解决此错误引起:java.lang.ClassNotFoundException [英] How to resolve this error Caused by: java.lang.ClassNotFoundException

查看:1241
本文介绍了如何解决此错误引起:java.lang.ClassNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个控制台应用程序 helloworld.java 并运行 javac helloworld.java ,然后 java helloworld 。这很好。

I wrote a console application helloworld.java and ran javac helloworld.java,and then java helloworld. This worked fine.

然后我创建了一个包 com.abc.project 并将helloworld.java移入其中(正确生成了package import语句,它是 package com.abc.project; )。然后我运行 javac helloworld.java 这个工作也很好并且正确地生成了这个类。

I then created a package com.abc.project and moved helloworld.java into it(the package import statement is correctly generated which is package com.abc.project;). And then i ran javac helloworld.java this worked also fine and generated the class properly.

然而,当我从控制台运行 java com.abc.project.helloworld ,它抛出了找不到类错误。

However, when I ran java com.abc.project.helloworld from the console, it threw an "class not found" error.

请问有人可以提出什么问题吗?

Please can anyone advise what is the problem?

推荐答案

尝试运行

java - cp ABSOLUTE_PATH com.abc.project.helloworld

其中ABSOLUTE_PATH指的是包含类文件的目录。说它是 bin 生成类文件的目录以及与源文件相同的目录结构

Where ABSOLUTE_PATH refers to the directory where the class files along with packages are present. say it is bin directory where the class files are generated along with same directory structure as source files

这篇关于如何解决此错误引起:java.lang.ClassNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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