English 中文(简体)
Recompile to *.Jar After decompile and fix the Code?
原标题:Recompile to *.Jar After decompile and fix the code?

I have a myfile.jar file. I use jd-gui to decompile all *.class in a folder in myfile.jar. I get many *.java files in many folders

After fixing some code in some *.java, now I would like to recompile all *.java back to *.class, and pack the whole folder back to myfile.jar.

How do I do this?

(这是我第一次采用java法典。)

问题回答

你们需要一个Java Development Kit(JDK)。 这包括一名 Java汇编员(通常称为javac)和一名jar档案管理员。

假设你在名录上有java文档src (根据其组合结构)

javac -d classdir -sourcepath src src/*.java src/*/*.java src/*/*/*.java ...

to compile all files. (Adjust the number of * to the number of directory levels. If you only have some folders with source files in them, you can also list them individually. If some classes depend on others, you can ommit the others, the compiler will find and compile them automatically.)

If the program needs external libraries, provide these with a -classpath argument.

现在,我们都在名录上汇编了各种课程:statdir。 查阅你原来的杰尔档案:那里的任何非阶级档案也应抄送给您的班子(其前身的相对目录)。 其中最显著的内容是META-INF/MANIFEST.MF

然后,我们从这些档案中产生新的jar。 The jar tool is included in the JDK.

jar cfm mypackage.jar classdir/META-INF/MANIFEST.MF -C classdir .

(You can also simply use a zip program of your confidence and rename the resulting zip file to .jar. If your files have non-ASCII names, make sure to set the filename encoding to UTF-8.)

总而言之,将 Java编成需要javac的可执行类别。

九:

${JAVA_HOME}/bin/javac -d OUTPUT_DIRECTORY SOURCE_FILES

视窗:

%JAVA_HOME%injavac.exe -d OUTPUT_DIRECTORY SOURCE_FILES

一旦您汇编了该法典,你便可创建该手册(这是一个包含所有类别和一些有关创建者、版本、......etc的元数据的文件)。

${JAVA_HOME}/bin/jar cf output.jar INPUT_FILES

您可以阅读更多关于您可以使用的不同选择:javac 。 使用像ant这样的工具使汇编源代码和制造焦炭更容易。 见rel=“nofollow”>、javac

由于我难以完全对杰尔案卷进行改编,并配合我的申请,我在此要谈谈先前的答复中遗漏的步骤。

在我的具体案例中,为了尽可能方便地做事,我只想修改一份java案卷,以补齐,并在杰尔案卷中直接加以更新。

I started from the answer from Paulo Ebermann, and I ended up with:

javac -source 8 -target 8 -d classdir -cp 
"
path/to/dep1.jar; 
path/to/dep2.jar; 
path/to/myoriginal.jar 
" path/to/my/java/class.java

cd classdir
jar -uf path/to/myoriginal.jar path/to/my/java/class.class

Notes:

  • the path/to/myoriginal.jar which is in the path of the dependencies, this forces the java compiler to look for missing classses in the original .jar file rather than in the local decompiled code (which would require recompilation and more dependencies) and therefore I have intentionally left out the . path in the list of class paths
  • the -source 8 -target 8 which were required to force the class to compile for the appropriate version of the runtime machine.
  • the -uf which indicates that the jar tool should only update the file with the provided class




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签