【问题标题】:How to compile an edited java file into a class class file that's a part of a package [Related to Minecraft]如何将已编辑的 java 文件编译成作为包一部分的类类文件 [与 Minecraft 相关]
【发布时间】:2017-05-03 15:51:14
【问题描述】:

所以我试图编辑一个 .jar 文件中的类文件(.jar 文件还有一些其他类,但我只是想编辑这个)。我为这个特定的类使用了源 .java,但我无法将它编译成一个类,因为编译器会调用错误,因为它是从包中调用东西。

有人知道问题出在哪里吗?

或者,如果有人知道有一个程序可以让我直接编辑 .jar 文件中的 .class 文件的代码,而无需进行所有的反编译和重新编译,那将非常有帮助。

额外信息

  1. .jar 文件是我为朋友准备的 Minecraft 模组。
  2. 原始 .class 的代码(有效):

    package pw.cinque.cpsmod;
    import cpw.mods.fml.common.eventhandler.SubscribeEvent;
    import cpw.mods.fml.common.gameevent.TickEvent;
    import cpw.mods.fml.common.gameevent.TickEvent$ClientTickEvent;
    import net.minecraftforge.client.event.MouseEvent;
    
    import cpw.mods.fml.common.eventhandler.SubscribeEvent;
    import cpw.mods.fml.common.gameevent.TickEvent;
    import net.minecraftforge.client.event.MouseEvent;
    import pw.cinque.cpsmod.CPSMod;
    
    public class ClickListener
    {
      public ClickListener() {}
    
      private boolean hasClickedThisTick = false;
    
      @cpw.mods.fml.common.eventhandler.SubscribeEvent
      public void onMouse(MouseEvent event) {
        if (button != 0) {
          return;
        }
    
        if ((CPSMod.preventDoubleclicks) && (buttonstate) && (hasClickedThisTick)) {
          event.setCanceled(true);
          return;
        }
    
        if (buttonstate) {
          hasClickedThisTick = true;
          CPSMod.addClick();
        }
      }
    
      @cpw.mods.fml.common.eventhandler.SubscribeEvent
      public void onClientTick(cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent event) {
        hasClickedThisTick = false;
      }
    }
    
  3. 我编辑的文件代码:

    package pw.cinque.cpsmod;
    
    import cpw.mods.fml.common.eventhandler.SubscribeEvent;
    import cpw.mods.fml.common.gameevent.TickEvent;
    import cpw.mods.fml.common.gameevent.TickEvent$ClientTickEvent;
    import net.minecraftforge.client.event.MouseEvent;
    
    import cpw.mods.fml.common.eventhandler.SubscribeEvent;
    import cpw.mods.fml.common.gameevent.TickEvent;
    import net.minecraftforge.client.event.MouseEvent;
    import pw.cinque.cpsmod.CPSMod;
    
    public class ClickListener {
        private boolean hasClickedThisTick = false;
        int newVar = 0;
        @SubscribeEvent
        public void onMouse(MouseEvent event) {
            if (event.button != 0) {
                return;
            }
            if (CPSMod.preventDoubleclicks && event.buttonstate && this.hasClickedThisTick) {
                event.setCanceled(true);
                return;
            }
            if (event.buttonstate) 
            {
                this.hasClickedThisTick = true;
                CPSMod.addClick();
                newVar = CPSMod.getClicks();            
                if(newVar > 5)
                {
        CPSMod.addClick();
    
        }
    }
    }
    
    @SubscribeEvent
    public void onClientTick(TickEvent.ClientTickEvent event) {
        this.hasClickedThisTick = false;
    }
    }
    
  4. 这些是我尝试编译时收到的错误消息。

ClickListener.java:2: error: package cpw.mods.fml.common.eventhandler does not exist
     import cpw.mods.fml.common.eventhandler.SubscribeEvent;
                                            ^
ClickListener.java:3: error: package cpw.mods.fml.common.gameevent does not exist
     import cpw.mods.fml.common.gameevent.TickEvent;
                                         ^
ClickListener.java:4: error: package cpw.mods.fml.common.gameevent does not exist
     import cpw.mods.fml.common.gameevent.TickEvent$ClientTickEvent;
                                         ^
ClickListener.java:5: error: package net.minecraftforge.client.event does not exist
     import net.minecraftforge.client.event.MouseEvent;
                                           ^
ClickListener.java:7: error: package cpw.mods.fml.common.eventhandler does not exist
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
                                       ^
ClickListener.java:8: error: package cpw.mods.fml.common.gameevent does not exist
import cpw.mods.fml.common.gameevent.TickEvent;
                                    ^
ClickListener.java:9: error: package net.minecraftforge.client.event does not exist
import net.minecraftforge.client.event.MouseEvent;
                                      ^
ClickListener.java:10: error: cannot find symbol
import pw.cinque.cpsmod.CPSMod;
                       ^
  symbol:   class CPSMod
  location: package pw.cinque.cpsmod
ClickListener.java:17: error: cannot find symbol
    public void onMouse(MouseEvent event) {
                        ^
  symbol:   class MouseEvent
  location: class ClickListener
ClickListener.java:40: error: package TickEvent does not exist
    public void onClientTick(TickEvent.ClientTickEvent event) {
                                      ^
ClickListener.java:16: error: cannot find symbol
    @SubscribeEvent
     ^
  symbol:   class SubscribeEvent
  location: class ClickListener
ClickListener.java:39: error: cannot find symbol
    @SubscribeEvent
     ^
  symbol:   class SubscribeEvent
  location: class ClickListener
ClickListener.java:21: error: cannot find symbol
        if (CPSMod.preventDoubleclicks && event.buttonstate && this.hasClickedThisTick) {
            ^
  symbol:   variable CPSMod
  location: class ClickListener
ClickListener.java:25: error: illegal start of type
        if (event.buttonstate) {
           ^
ClickListener.java:27: error: cannot find symbol
            CPSMod.addClick();
            ^
  symbol:   variable CPSMod
  location: class ClickListener
ClickListener.java:28: error: cannot find symbol
      gay = CPSMod.getClicks();
            ^
  symbol:   variable CPSMod
  location: class ClickListener
ClickListener.java:33: error: cannot find symbol
          CPSMod.addClick();
          ^
  symbol:   variable CPSMod
  location: class ClickListener
17 errors

【问题讨论】:

    标签: java class jar compilation


    【解决方案1】:

    您需要编译该类及其所有依赖项,否则它将无法工作。可能你应该从那个 .jar 中获取所有文件,进行你想要的修改,然后再次编译和压缩它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-29
      • 2010-09-21
      • 2020-01-10
      • 2014-03-28
      • 2011-06-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多