如何在java中编译包

wnavrhmk  于 2023-06-04  发布在  Java
关注(0)|答案(1)|浏览(201)

我是java新手,如何在Intelij中编译包
这是我的目录

它在www.example.com上运行得很好Main.java
为了编译,我首先运行
javac people/People.java
然后我编译javac Main.java,它返回Main.java:8:错误:软件包com.amigoscode.people不存在
Main.java

package com.amigoscode;

// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`,
// then press Enter. You can now see whitespace characters in your code.

import java.util.Scanner;
import com.amigoscode.people.People;

public class Main {

    public static void main(String[] args) {
        People p = new People();
        System.out.println(p.fullName());
    }

}

People.java

package com.amigoscode.people;

public class People {

    public String fname = "John";
    public String lname = "Doe";
    public int age = 24;

    public String fullName() {
        String fullName = fname + " " + lname;
        return fullName;
    }

}

非常感谢。

9fkzdhlc

9fkzdhlc1#

首先,使用terminal导航到src目录。然后执行下面的命令来编译People.java

javac com/amigoscode/people/People.java

现在,要编译Main.java,请执行以下命令。

javac com/amigoscode/Main.java

这个应该没问题

相关问题