如何运行不同目录中的Java类文件? [英] How to run java class file which is in different directory?

查看:206
本文介绍了如何运行不同目录中的Java类文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目录路径:

c:\home\test\src\com\bsoft\conc

我在 src 文件夹中有我的Java程序并且我的课程文件放在 conc 文件夹中。
我需要从 home 文件夹运行我的Java程序。当我运行时出现错误:

I have my java program in src folder and I have my class file in conc folder. I need to run my java program from home folder.When I run I'm getting error:

could not find or load main class


推荐答案

在我的程序中, com.bsoft.conc 是一个程序包名称,用于存储已编译程序的类文件。如果必须从 home 文件夹中,我们必须指定
java -classpath test\src com.bsoft.conc。类文件名

In my program com.bsoft.conc is a package name where my class file for the compiled program will be stored.If I have to run that from home folder we have to specify java -classpath test\src com.bsoft.conc."class-file-name"

这是因为我们需要告诉JVM它必须在哪里查找类文件。

This is because we need to tell the JVM where it has to look for class file.

因此,我们必须使用 test\src 然后是
类文件位置 com.bsoft.conc.class-file-name

so , we have to specify navigation to the src using "test\src" and then class file location "com.bsoft.conc.class-file-name"

如果您在高级设置中设置了环境变量,那么如果您在cmd中指定类路径,它也会被覆盖

If you have set environment variable in advanced settings then it will also be overriden if you specify classpath in cmd

这篇关于如何运行不同目录中的Java类文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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