Search code examples
javacompilation.class-file

Create .class file from a jar file -java


I am using Java8. I have one .jar file containing .class files.

I downloaded the source code of the same .jar file. And I edited one of the file in it. It is .java file.

Now I want to compile all these .java files in the source code and create a new .jar file with .class files

Any clues?


Solution

  • 1) Compile the classes (javac command)

    If you don't have any jar dependencies required at compile time, you should not need to set the classpath. Otherwise you should specify the cp argument with.
    Example (Unix way) :

    javac -cp "myLib.jar:myOtherLib.jar" *.java   
    

    2) Then create a jar from these compiled class (jar command)

    Example :

    jar cf myjar myFolderWithCompiledClass