在命令行中使用包编译 Java 代码时出错? [英] getting error when I compile the Java code using package in commandline?

查看:31
本文介绍了在命令行中使用包编译 Java 代码时出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个目录结构:

project1/src/edu/course/firstweek/javacourse/Program1.java

上面一个包中的另一个文件:

Another file in one package above:

project1/src/edu/course/firstweek/program2.java

在program2.java的头文件中,我有

In the header of program2.java, I have

package edu.course.firstweek;

import edu.course.firstweek.javacourse.Program1;

现在到当我在命令行中运行以下命令时:

Now to when I run the following in commandline:

Javac src/edu/course/firstweek/program2.java, 我收到这个错误:

src/edu/course/firstweek/program2.java:14:error cannot find symbol
      System.out.println(program1.print("hello world"));

   symbol:   variable Program1
   location: class program2
2 errors

我可以看到编译器无法找到 program1,但是我在 中有正确的 import package 语句程序2.我这里需要帮助,编译后,运行程序有什么需要考虑的.

I can see that the compiler is not able to find the program1,but I have the correct import package statement in program2. I need help here and after compiling, is there something that needs to be taken into account for running the program.

谢谢

推荐答案

尝试进入里面的一个目录,即 cd src然后编译Javac edu/course/firstweek/program2.java

Try going into one directory inside, i.e. cd src and then compile Javac edu/course/firstweek/program2.java

为了运行,做java edu.course.firstweek.program2

这篇关于在命令行中使用包编译 Java 代码时出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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