我是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
这是我要在其中使用这些类的Main类:
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
javac用于编译,在编译时,您使用“ /”(Windows)或“ \”(基于Unix)和.java文件后缀来引用文件路径:
java用于执行已编译的类。您使用“。”引用.class编译文件。没有后缀.class文件: