简体   繁体   中英

How to compile .class files

I am new to Java, I have some *.class files which needs to be modified. Now I de-compiled these *.class files to get the source code using the famous JD Decompiler . The concern is after I change the code and need to recompile these *.class files how will I do it with Eclipse. I only the compiled *.class files.

I know its a stupid question but bear with me I'm .NET Developer with a few days into Java.

You can not compile a *.class file, Its already compiled code (bytecode) for its *.java source. I think you need to copy the code from JD Decompiler's editor to a java source file.

ie copy the source code from JD's editor for Hello.class into a file named Hello.java . Now you can move this file in IDE of your choice or directly compile using javac. (dont forget to put all the dependencies/required jars/source in project build path)

I think that you can use javac.

For example, if you have three .java files:

source1.java
directory\\source2.java
directory\\directory2\\source3.java

Execute:

javac source1.java directory\source2.java package\package2\source3.java

And you can create a file.jar with all .class:

jar cf file.jar source1.class directory\source2.class directory\directory2\source3.class

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM