【问题标题】:Java built and run successfully in IntelliJ IDEA but failed to compile in Mac terminalJava 在 IntelliJ IDEA 中构建并运行成功,但在 Mac 终端中编译失败
【发布时间】:2022-01-03 12:54:13
【问题描述】:

我在 IntelliJ IDEA 中编写了我的 java 代码,它的构建和运行都非常好,但是当我尝试在我的 Mac 终端中使用 javac 编译代码时,我不断收到以下错误:

% javac Main.java 
Main.java:34: error: cannot find symbol
com.business.Helper clsHelper = new com.business.Helper();
            ^       
symbol:   class Helper

location: package com.business

我的 Main 和 Helper 类都在同一个包 (com.business) 中,所以我不明白为什么 javac 不能工作。

提前致谢。

【问题讨论】:

  • 您还没有告诉我们您的文件结构是什么样的,但我怀疑您需要将两个目录放在更高的位置,并使用javac com/business/Main.java
  • 你还需要确保在编译Main.java之前编译Helper.java
  • 谢谢乔恩,我已经做到了,同样的问题。
  • 好点Ole,我先编译Helper.java看看。

标签: java intellij-idea compiler-errors


【解决方案1】:

通过构建工件(构建 .jar 文件)解决了我的问题,并运行使用它在我的终端中运行 .jar 文件: java -cp xxxx.jar xxx.xxx.Main 其中 xxx.xxx 是具有 Main(入口点)的包。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-21
    • 2014-02-05
    • 2014-04-04
    • 2020-10-13
    • 2017-02-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多