为编译和运行 Java 包设置正确的类路径? [英] setting the correct classpath for compiling and running Java packages?

查看:37
本文介绍了为编译和运行 Java 包设置正确的类路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在使用Eclipse,其中compilerunning 程序非常简单.设置classpath 不需要做太多工作.但显然,当从 commandLine 运行它们时,情况并非如此.当我从 terminal 尝试 compiling 时,我遇到了各种错误.我正在粘贴项目 cp125_solnmy package structure 的图像.现在我想在 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 中没有 com.scg.util.*.所以我尝试了

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 如何工作以及如何在 command-line 中提供它的不同文章.但是当谈到包级结构时,我找不到关于如何COMPILE and RUN包的好教程.如果能在这里提供一些关于编译和运行这类的正确方式的帮助,那将是非常有帮助的.

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屋!

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