How to compile a single Java file

后端 未结 2 903
傲寒
傲寒 2020-12-13 04:26

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

相关标签:
2条回答
  • 2020-12-13 05:05

    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 讨论(0)
  • 2020-12-13 05:24

    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

    0 讨论(0)
提交回复
热议问题