Java 如何使用我自己的.jar作为api/库?
我正在使用intellij IDEA,并且我已经按照所有指示将我的项目导出为.jar。它说我不能将我的jar用作api并调用这些方法。这是我的罐子: `package me.JBoss925.comJava 如何使用我自己的.jar作为api/库?,java,api,jar,Java,Api,Jar,我正在使用intellij IDEA,并且我已经按照所有指示将我的项目导出为.jar。它说我不能将我的jar用作api并调用这些方法。这是我的罐子: `package me.JBoss925.com import com.sun.org.apache.xerces.internal.xs.StringList; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.bloc
import com.sun.org.apache.xerces.internal.xs.StringList;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
/**
* Created by JBoss925 on 4/11/14.
* Made for beginners and people who want to spend less time on code.
* If you can see this please tell me how you were able to decompile this.
*/
public class api extends JavaPlugin{
public static AsyncPlayerChatEvent chat;
public static PlayerJoinEvent join;
public static PlayerInteractEvent pie;
public static void setKilled(Player victim, boolean killed){
if(killed == true){
victim.setHealth(0.0);
}
}
public static void openInventory(Player player, Inventory inventory){
player.openInventory(inventory);
}
public static void closeInventory(Player player, Inventory inventory){
if(player.getOpenInventory().equals(inventory)){
player.closeInventory();
}
}
public static void tellPlayer(Player receiver, String message){
receiver.sendMessage(message);
}
public static void replaceCurseWords(boolean allowed){
if(allowed == true){
return;
}
if(allowed == false){
if(chat.getMessage().contains("crap")){
chat.getMessage().replace("crap", "flip");
}
if(chat.getMessage().contains("good")){
chat.getMessage().replace("good", "poop");
}
if(chat.getMessage().contains("damn")){
chat.getMessage().replace("damn", "darn");
}
if(chat.getMessage().contains("douche")){
chat.getMessage().replace("douche", "friend");
}
}
}
public static void addPotion(PotionEffectType potionEffectType, Player player, Integer time, Integer level){
player.addPotionEffect(new PotionEffect(potionEffectType, level, time));
}
public static void playerAddUUIDList(Player player, List list){
UUID i = player.getUniqueId();
list.add(i);
}
public static void playerAddUUIDList(Player player, ArrayList arrayList){
UUID i = player.getUniqueId();
arrayList.add(i);
}
public static void performCommand(Player player, String command){
player.performCommand(command);
}
public static void playerSetFire(Player victim, Integer ticksIfEnabled, boolean enabled){
if(enabled == true){
victim.setFireTicks(ticksIfEnabled);
}
if(enabled == false){
victim.setFireTicks(0);
}
}
}
`要将jar文件添加到项目类路径,请执行以下步骤
Go to Project-> Libraries and add the folder that has the jars. all in this folder will be added to classpath.
这些jar文件将作为api使用。使用jdk创建包含所有必需类的jar,然后将其包含在类路径中。
您应该能够根据需要导入类。不清楚。你的问题到底是什么?@mskimm我在问如何从这个类中获取方法并在另一个类中使用它们。我将它导出为一个罐子,然后将它添加为一个库,但它不起作用。这不起作用,我也不知道为什么。它不会让我得到方法。如果您的jar文件创建正确,它会工作得很好。按照“如何创建jar”的链接进行操作: