Re-building a deleted class file in Eclipse

前端 未结 5 1568
走了就别回头了
走了就别回头了 2021-02-09 19:06

I accidentally deleted a .class (Java bytecode) file in my project (on the filesystem, not using Eclipse itself). Easy to fix, right? Just re-build it. But that doesn\'t work! E

5条回答
  •  误落风尘
    2021-02-09 19:28

    In more traditional languages, programs are loaded all at once as part of the startup process. Java doesn’t have this problem because it takes a different approach to loading. This is one of the activities that become easier, because everything in Java is an object. Remember that the compiled code for each class exists in its own separate file. That file isn’t loaded until the code is needed. In general, you can say that “class code is loaded at the point of first use.” This is usually when the first object of that class is constructed, but loading also occurs when a static field or static method is accessed.

    If You can't restore from local history. Then you are out of Luck. Use Source Control Management Tools like SVN or Git to avoid such surprises next time.

    If you are having source file try to compile file along with dependencies alone in console or other IDE and copy that class file let the errors be errors now edit source file in eclipse try to build again. Hopefully this will not work because even eclipse will neglect Re-compiling some files while building Project. Better Give a Try.

提交回复
热议问题