Re-compile a Java Class from Jar

19,342

Solution 1

You will want to compile your file like so:

javac -classpath C:\folder\where\jar\is\the_jar_file.jar file.java

per the javac usage instructions:

C:\Console2>javac -help
Usage: javac <options> <source files>

Solution 2

Once you've compiled the new file (such as in Mr. Will's answer), you can add the new file to the jar using:

jar uf C:\folder\where\jar\is\the_jar_file.jar file.class
Share:
19,342
Admin
Author by

Admin

Updated on August 03, 2022

Comments

  • Admin
    Admin over 1 year

    I have an executable jar that has one class file with a wrong value. I requested that file from the author and corrected the value.

    Now I want to compile it and add the compiled class file into the jar and run it.

    Not surprisingly I get multiple "cannot find symbol" errors for references of custom object that were in the jar file.

    I tried to compile the file by referencing the jar file in the classpath like so

    C:/> javac  file.java  -classpath C:/folder/where/jar/is
    

    but this doesnt seem to work... I get the same errors as if just doing

    C:/> javac file.java
    

    Is there a way to compile this individual class somehow referencing the other files in the jar?

    Thanks.


    Errors I am getting while following some of the suggestions below here:

    javac -classpath C:/jar/location.jar File.java
    
    File.java:226: cannot find symbol
    symbol  : class Stuff
    location: class com.shared.stuffers
                                  Stuff s1 = new Stuff();
                                                 ^
    

    Stuff class is found in the Jar, but can not be seen by the javac program... I feel like I am doing something wrong but not sure where? Thanks.

  • Admin
    Admin almost 15 years
    Thanks for suggestion --- but issue remains :(
  • mjn
    mjn almost 15 years
    The base directory (.) is missing. Command should be javac -classpath .;C:\folder\where\jar\is\the_jar_file.jar file.java