开发者

How to compile a single Java file

I have searched this, but I could'n find or understand what I found.

Now I'm not a Java programmer, but I have the need to compile a single Java file into an existing (compiled) Java program. The source of this Java code is not available to me, therefore I cannot compile the entire project.

I'm not interested in decompiling the original project.

How to quickly do this using only the JDK and javac? (Through the command line is what I prefer.)

I 开发者_Python百科understand that to do so error checking outside of the single java file will have to be disabled, because it can't read the dependencies.

Thanks in advance,

-Aidiakapi

EDIT: I do have the JAR file, thanks for the answer :)


As far as I can understand you want to re-compile a single java file and replace it in an existing jar file..

So you compile it..

cmd>javac -classpath jar1.jar;jar2.jar my.company.MyClassToReplace.java

and replace it in the jar.

cmd>jar uf myJarFile.jar my/company/MyClassToReplace.class


You need to have the jar(s) which contains all the things your class depends on to compile it.

You can then compile the Class with

javac -classpath jar1:jar2 mypackage.MyNewClass

If you have no access to the original Jars, you will have to create mock classes and method etc (which don't have to do anything, just be there so your class compiles) Using an IDE can make both processes easier. (That is what it is for ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜