I have decompiled a jar file,
and made two classes from it. After that, I tried to make a new jar file with these two class files, using this code
jar cvf AB.jar WinRegistry.class StartPageChangeApplet.class
The file created without any errors. However, when I look at the source code on Java Decompiler, it says "Internel Error", means that I couldn't make the jar file properly.
Where am I doing doing wrong ?
Please define "made two classes from it". Which java compiler (e.g. javac.exe) are you using? Did you just copy the source to a .class file without compiling maybe?
The java decompiler JAD actually displays source code, not class bytecode. Don't get confused by the title of the editor which is saying WinRegistry.class.
So you can't just save that as a .class. You need to save it as a .java and then compile it to .class using a java compiler:
javac WinRegistry.java StartPageChangeApplet.java
jar cf AB.jar WinRegistry.class StartPageChangeApplet.class
From Eclipse, you can do this way..
Related
I was decompiling a jar file to see if i could look at the source code, however, I saw that instead of .class files in the .jar file, there were .lclass files. I did some googling and came up with nothing, the only slight thing I could gather is that it means "local class" but I dont think that is the case as ALL of the classes in the jar file are .lclass. This was meant for Java 8.
Rename it to .class file :D (.lclass -> .class) and then decompile!
it's my first time working with a .class file in java, I saw that a.class file is just a compiled java code, so I figured out I should add this class to my package and it should work like a regular java class file but it didn't, I'm working with Netbeans by the way.
the problem is that I cant use this class, the main class doesn't recognize it, asking me if I want to create a Rational class to fix the error
I am not entirely sure what you want to do with the class file, but my assumption is that you got it already in this form and want to use some of it's methods.
So if this is correct you should put the file in the folder that netbeans uses to store .class files
(in my case build/classes/java/main/Testing):
IDEs almost always store .class files in a separate directory so that you don't have to deal with them, because a .class file is compiled java code and in 99% of the cases you won't touch the .class file but you will change the .java file and compile it to a class file.
Also be careful if your .class file is a part of a package you should replicate the structure of the package like answered here.
Suggest I have a HelloWorld.jar file, this file contains only HelloWorld.java , which is the source code of the application.
Will it be possible to run this jar file and execute the application, even though I don't have HelloWorld.class?
Yes, it can be done: See the javax.tools api. It is not easy, but it can be done....
You will likely be better off with a script that unjars the file, compiles it, and runs it.
Directly? No. java accepts only classfiles. To use source it must be compiled with javac. Nothing keeps you or a utility from compiling the source files to class files and using those, however.
Is this possible to convert a .class file (from .jar external library) to a .java file? I'm trying to figure out whether it is possible or not because the source of the external library is unavailable.
What are the steps I need to take to do this?
use a java decompiler like "Cavaj". It will open the class into a txt format, copy the code to a file and save as .java
Use jad. Download it from here. It works fine with classes compiled up to SDK 1.4... 1.5, if I recall correctly.
The javap command takes class-names without the .class extension. Try
javap -c ClassName
javap will however not give you the implementations of the methods in java-syntax. It will at most give it to you in JVM bytecode format.
To actually decompile (i.e., do the reverse of javac) you will have to use proper decompiler.
http://download.cnet.com/Cavaj-Java-Decompiler/3000-2213_4-10071619.html
or may be this be of some help Java Decomilers
it is Possible to convert a class file to java file without using any tools . e.g Decompiler or something else ?
I'm quite green to java (I program in C/C++) and I still haven't figured out how this all works together.
I'm not trying to ask for anyone to do my homework, I'm just confused about some basic java stuff. I have an assignment which wants me to create a maze. The assignment comes with some files which have been pre-implemented and theoretically works. The folder gives me some .java files and some .class files. I opened the .java files and most of them are interfaces with no real code, so I'm assuming the meat of it are in these .class files. My question is, how do I interface with these .class files? do I need to do something like import myClass; if I have a file called myClass.class?
I've tried importing the file directory which these files are contained in (through Eclipse), but it seems the .class files don't show up. I'm guessing it's being processed in the background?
Here's a link to the assignment
http://www.ics.uci.edu/~goodrich/teach/ics23/LabManual/Dark/
Here's the zip file with all the .java and .class files
http://www.ics.uci.edu/~goodrich/teach/ics23/LabManual/Dark/Dark.zip
Thanks in advance!
To add .class files to your project in Eclipse: right-click your project, select properties --> Java Build Path --> Libraries and click on Add Class Folder button. Select the folder with the classes.
No you won't need to import. Place the class files in the same folder so their path is included and simply call on them like normal datatypes.
For example:
myClass mc = new myClass();
or
(new myClass()).myRoutine();
If some method is static
myClass.staticalicious();
importing is used generally when path to classfiles needs to be specified.
Also, .class files are simply compiled .java files.
Oh and lastly, follow Java nomenclature :)
It would be MyClass, not myClass.
.class files are compiled versions of .java files. Assuming that the .class files are named and packaged appropriately you should be able to reference them like this:
Filename: some.package.class
Code: import some.package;
Once you've imported the package you can call methods on the classes contained therein.
As others mentioned, the class files are the compiled Java files, so no there is not "more meat" in them than you can see in the source files. There are class files for interfaces and class files for implementations.
I assume you just use the default package.
So just set the classpath to the directory holding these pre-compiled classes:
e.g. to compile your classes on a Linux/ Unix system:
javac -classpath <dirWithClassFiles>:. .....
and to run the application:
java -classpath <dirWithClassFiles>:. .....
You then can directly use those pre-compiled classes in your own classes.
class files are the binary output of the java compiler. they are the java equivalent of .o files in C or C++ the "meat" in this instance is probably for you to implement.
The java compiler handles finding and including the necessary files, you may need to import some.package.name.*; to avoid having to use full class names (e.g. SomeClass instead of some.package.name.SomeClass)
The class files are compiled classes and you cannot view them in your IDE. Your IDE will allow you to import them but just drop off the extension...
import example.some.Thing;
The .java files are the source files that were most likely used to compile the .class files. I'm sure they are that just for your reference.
Eclipse IDE does not show the .class files. you can add the jars or class files to your project build path. And then you can import the perticular class to your own class to use it.