Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I would like to unzip a jar library that I am using check the classes if it's core functionality is updated to what is presented on GitHub.
How do you unzip a .jar file?
Update:
You wont be able to get class .txt without the source code attached to them if you unzip the directly.
Thanks, to alegen's method of using a Java Decompiler you can decompile classes.
Open the JAR file with WinRAR but unless the people also packaged the source code, you will only find .class files which contain bytecode. You will have to also use a decompiler; I usually use JD Java Decompiler.
You can extract files from JAR file using a variety of tools, including plain ZIP file tools ... and of course the jar command that comes as part of the JDK.
It sounds like your real problem is that you want to decompile the .class files in a JAR file so that you can compare them with some Java source code.
Well, the bad news is that it won't work ... especially in the large-scale. Yes, there are decompilers that will (on a good day) produce something that resembles Java. However:
The decompiled Java won't look anything like the original source code that were used to produce the .class files. Comparing the decompiled files with the original source code (or something based on the original source code) is going to be a tedious and difficult MANUAL process.
There is a fair chance that the decompiled code won't even be valid (compilable) Java.
A better approach might be to compile the sourcecode on GitHub and try to compare the two versions of the .class files. However, even that isn't straight forward because:
The .class files contain timestamps, and other stuff that depend on build paths, compilation switches, and so on. You have to figure out how to remove this "noise" when comparing the .class files.
Different versions of the Java compiler produce different flavours of classfile.
Even when the classfile version numbers are the same, there can be compiler-version-specific differences in the generated bytecodes.
For small-scale comparisons, decompilation might do ... provided you are prepared to work at the problem. You could also use javap to print the bytecodes in the class files and compare the javap outputs.
So what you want do do is to check if two jars are the same, to ascertain that the methods on github are the same as the ones in your jar?
I think you're trying to solve the wrong problem here. What you should do is to just check out the code from github and build it yourself. There should be a file called README, INSTALL or something similar in the root directory of the project.
Now, of course, you might not want the newest version of the project, you might want the latest stable release or whatnot, which is perfectly doable: Just download the release you want from git, and build yourself. You now have both the code, and a jar.
If you do this, you are ensured that the code matches the jar, and no icky decompilation is needed, just a quick make or ant later, as specified by the readme file.
Related
Started coding in java , just wanted to see the implementation of classes and interfaces we actually import to use their methods.
Ex:
import java.util.Scanner;
I am curious to see what's inside the class Scanner(){}
Is that possible?
Tried Searching but couldn't find the implementation and definitely did not understand how they hide them from public.
Please follow the following Steps to See Java predefined classes implementation
1) Get rt.jar (It contains all Core Java API Classes which required for JRE at Runtime)
Download it from the internet directly or Search it in JDK at Path like C:\Program Files\Java\jdk1.8.0_181\jre\lib and copy it to other location on your Desktop
2) Extract the copy of rt.jar
Extracting .jar file with command line
https://www.wikihow.com/Extract-a-JAR-File
After extracting you can see all the Core Java Classes in .class file (cant read it Directly) which we use normally in our programs
3) Download tools like cavaj java decompiler to open and read .class file
You Can see any code in Any jar with this approach... Its very smart way to understand basics of java with fun ..
There is nothing "hidden from public" concerning java.util.Scanner.
#shmosel already linked to the source of it, #Stultuske pointed out, that there are various websites covering source code of java.
Modern IDEs also allow you to view into source for your libraries (aka .jar files).
My Netbeans IDE shows source from known jar files whenever I ctrl-click on a class.
Same goes with Eclipse, IntelliJ, ...
For a lot of open-source libraries (e.g. from Apache) there is also source code available. Just by cloning the version control repository, downloading source packages (zip, ...-source.jar) or browsing the version control repository online.
If project is buildable with maven, the IDE can even download and show sources for open source project automatically.
This question already has answers here:
Including jars in classpath on commandline (javac or apt)
(5 answers)
Closed 4 years ago.
I need to use a library (JDOM) in my program, but I can't figure out how to use it without eclipse (I know on eclipse it is "build path" or something like that).
Can anyone help me please ?
Thanks
You do not install java libraries.
In the end, a Java library is nothing but one (or more) JAR archives that sit on your file system. Thus, "installing" boils down to:
identify the JARs to download
download them
put them in a known space in your file system
Then, when compiling/running a Java application that is supposed to use these libraries, you have to ensure that your classpath setup points to the correct JARs.
Typically, you want to use a Java library as part of one of your projects (a library does nothing for you, it needs to be used by a program to be useful). So the normal approach is that you have a project directory somewhere, and in there, you might have a libs subdirectory for example.
But I guess the real answer here is: learn about build system such as maven or gradle. These tools help you building java applications, and they also give you a "model" how to structure your java projects. And they take care of downloading libraries and such things, too.
I have one War files (a Java application) consist of 64 class file along with image/CSS/JS files. I have lost the source of this war file. Now I want to do some changes in code. I am looking for some expert advice from community on following questions.
Is there best way to convert .class files to .java file without losing any section of code?
What are the tools if any for this task?
What are challenges/drawbacks of converting .class files to .java files to recreate war file?
If you do not want to spend horrible times in understanding decompiled bytecode, please start using a version control system and a remote repository for any project of more than two classes.
In particular, you can use Git with GitHub, open source are hosted for free while if you want to protect your code you can get a commercial subscription which is cheap anyway.
For this time, help yourself with a java decompiler such as JD:
Use a java decompiler to decompile the bytecode.
Create a git repository out of the decompiled java classes
Constantly synchronize it with the remote repository
Conversion to Java Bytecode is almost completely reversible. As #StephenC said, In the regenerated sources, you will lose comments, names of local variables etc. It might not compile right away but you should be able to get it to compile again, with a little modification.
You need a Java Decompiler to do that. Try JD-GUI or DJ Java Decompiler
In case you obfuscated your sources, the sources you recover will not be harder to understand and reverse engineer. Otherwise, with just a little tinkering, you should be able to get back your sources.
first i'd like to point out that im fairly new to netbeans and java, couldnt exactly find what i need on the web.
I downloaded a software's source files and was modifying it on netbeans. naturally when building the project, netbeans creates in (for example) documents/project_folder/dist/ a lib folder and the finished JAR file that i can use.
if i delete by mistake the source files, and would like to apply all the changes i previously made to fresh source files using the JAR and lib folder i still have, is it possible and how?
First of all it is not possible to get a source again from jar file in lib folder. Jar file is executable file which will just contain class files. You can use java decompilers to get source again.
NB do not has a version control nor auto save by default. You may have a look on git in NB7.
When you restore from Jar with decompiler there is a big chance to get the source back, even more if you know what your code is all about.
You can get the source back by using some decompiler. There are many decompilers available like DJ Decomipler. My favourite is Jd Java Decompiler. Its very small in size and does its job pretty well
I'm rather an Eclipse user but I guess both Eclipse and Netbeans are similar to a certain extent. Unless the jar has been created including the source, you won't have other choices that decompile the class files.
When needed, I usually go with JD-GUI which does a pretty good job decompiling jars.
It is not possible to retrieve exact source code from a compiled byte code. But there is a possibility to recover your code to some extent
JD is a good Java decompiler.
http://java.decompiler.free.fr/?q=jdgui
I think JD is a super hero in cases that the original source code is lost.
Keep your source code on any SCM. Use remote SCM not to loose your code. See: google code, github, launchpad etc.
Is there a Java equivalent to .NET Reflector?
Edit: more specifically, decompiling is what I'm after.
See How do I decompile Java class files? There's a link there to JD-GUI, which seems to be about what you're looking for.
Edit: Also see Open Java *.Class Files.
Edit 2: And Best free Java .class viewer?, which specifically mentions .NET Reflector.
From what little I know the functionality of .NET Reflector is available in pretty much all Java IDEs, including Eclipse. Just add a jar file to a projects and you can browse its classes just as you browse your own classes.
For the decompiler aspect (as opposed to the pure class browser) there are some alternatives as well. The JDK tool javap only decompiles to byte-code so it isn't really useful to get to the source code (but might help with getting an understanding of the code).
JAD is a pretty popular decompiler in the Java world and it produces compilable Java code most of the time (some bytecode sequences aren't easily translatable to valid Java 'though, so some corner cases exist).
You can get JAD for decompiling .class into .java. It's pretty good at it.
If you use Eclipse get the jadclipse plugin too. You'll need to configure the path to the jad.exe. Next time you open a .class you'll see the decompiled source instead of the .class declaration. And you can browse with F3 too. It's very useful.
I'm not super familiar with Java, but does JBrowser work for you?