设置正确的类路径来编译和运行Java包? [英] setting the correct classpath for compiling and running Java packages?
问题描述
我一直使用 Eclipse
最近,其中编译
和运行
程序很简单。在设置 classpath
时不需要做很多事情。但显然不是这样的情况下,从 commandLine
运行它们。当我尝试从终端
编译
时,我有各种错误。我正在粘贴项目 cp125_soln
的我的包结构
的图像。现在我想在 com.scg.domain
包中编译 Invoice.Java
,
我试过
I have been using Eclipse
lately, where compiling
and running
the program is very simple. Not much needs to be done in setting the classpath
. But apparently that is not the case when it comes to running them from commandLine
. when I try compiling
from terminal
, I am having various errors. I am pasting an image of my package structure
of the project cp125_soln
. Now I want to compile Invoice.Java
in the com.scg.domain
package,
I tried
javac src/main/java/com/scg/domain/Invoice.java
src/main/java/com/scg/domain/Invoice.java:17: error: package com.scg.util does not exist
import com.scg.util.StateCode;
.......................//long error message
这意味着我在 classpath $ c中没有
com.scg.util。*
$ c>。所以我尝试了
This means I do not have com.scg.util.*
in my classpath
. so I tried
javac -cp src/main/java/com/scg/util/* src/main/java/com/scg/domain/Invoice.java
src/main/java/com/scg/util/ListFactory.java:8: error: package org.slf4j does not exist
import org.slf4j.Logger;
^
src/main/java/com/scg/util/ListFactory.java:9: error: package org.slf4j does not exist
import org.slf4j.LoggerFactory;
^
src/main/java/com/scg/util/ListFactory.java:11: error: cannot find symbol
import com.scg.domain.ClientAccount;
^
symbol: class ClientAccount
location: package com.scg.domain
................... // long error message
我阅读了关于 classpath
工作,以及如何在命令行
中提供。但是当涉及到包级结构
,我找不到一个很好的教程如何 COMPILE和RUN
包。如果可以在编译和运行这些
packages
的正确方式提供一点帮助,它将非常有帮助。
I read different articles on how classpath
works and how to provide it in command-line
. but when it comes topackage level structures
, I am not able to find a good tutorial on how to COMPILE and RUN
packages. If a little help could be provided here on the propery way to compile and run
these kind of packages
, it will be very helpful.
推荐答案
javac src / main / java / com / scg / domain / Invoice.java
javac src/main/java/com/scg/domain/Invoice.java
尝试以下操作:
cd src/main/java
javac com/scg/domain/Invoice.java
这篇关于设置正确的类路径来编译和运行Java包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!