【发布时间】:2020-01-27 00:55:52
【问题描述】:
我是 Java 新手,我想在外部的 Main 类中使用我创建的 jar 文件中的类,但是当我尝试从终端编译时,它没有找到这些类。我不知道是我写错了 import 语句,还是我设置了错误的类路径。
jar文件完整地址:
/home/cristian/Escritorio/The\ complete\ Java\ developer\ course/Sección\ 11/Packages/ThejarFile/example/game/myJarFile.jar
主类完整地址:
/home/cristian/Escritorio/The\ complete\ Java\ developer\ course/Sección\ 11/Packages/com/cristian/example/Main.java
这是我要使用这些类的主类:
package com.cristian.example;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.List;
import ThejarFile.example.game.Player;
import ThejarFile.example.game.Monster;
import ThejarFile.example.game.ISaveable;
public class Main {
....
我试过这个:
~/Escritorio/The complete Java developer course/Sección 11/Packages$ javac -cp .:ThejarFile/example/game/myJarFile.jar com/cristian/example/Main.java
还有这个:
~/Escritorio/The complete Java developer course/Sección 11/Packages$ javac -cp .:/home/cristian/Escritorio/The\ complete\ Java\ developer\ course/Sección\ 11/Packages/ThejarFile/example/game/myJarFile.jar com/cristian/example/Main.java
【问题讨论】:
标签: java class jar package classpath