I'm an entry level programmer so please be descriptive in your responses.
I am trying to use a Java API given as a .jar file in my C# .net application. I don't know much Java, but this .jar file says "no main-class manifest attribute" when I try to run it so this means its a library? This Java API also comes with a .java file which shows how to use the library but I cannot see the code inside the .jar.
I found this question on this site, and one of the answers reads, "In simple way you can pack your java classes to jar file then In C# use Process class for execute and map IO stream." I am semi-familiar with the Process class in C# but I don't understand how I could use it to use a Java library in my C# .net project.
Is this possible? or was that answer incorrect?
If so, could you explain how I can use the .jar library in my C# app.
You can do it using IVKM.Net. IVKM.NET includes an application called ikvmc. Here’s the documentation for this tool:
http://www.ikvm.net/userguide/ikvmc.html
To use it compile your java code into a Jar.
Then run the ikvmc program:
ikvmc myCode.jar
If your jar contains a main() function, it will be converted into an exe that can be run on the CLR. Otherwise it will be converted into dll’s. To use the dll’s in your project just add them as references in Visual Studio and the same API that was available to you in Java will be accessible in your .Net application.
You can also include the IKVM.GNU.Classpath.dll dll from ikvmc and use the standard java class libraries in your application.
Have a look at IKVM ... it has tools to give you some level of interop. When you say Java API I assume you want to call some functionality from the jar rather than just execute it
You could use IKVM.NET - http://www.ikvm.net/userguide/ikvmc.html
On the official website in download - you can get
ikvmbin-7.2.4630.5 (Works up to Java 7)
However, on the owner's blog, you can download a newer version.
http://weblog.ikvm.net/default.aspx - You can get
ikvmbin-8.1.5717.0 (Works up to Java 8)
To create dll/exe use:
ikvmc hello.jar
On the other hand, if you can edit .jar lib (you created it) you
could use http://jni4net.com/ project.
This question already has answers here:
javac : Compiling a .java file which uses other classes in it
(2 answers)
How to compile a single Java file
(2 answers)
Closed 5 years ago.
Note: I'm only a student and don't have too much experience with programming, so please be patient with me.
I'm trying to modify the code of an existing program written in Java, so that the program runs exactly as normal except for my couple changes.
I found and unzipped the appropriate jar file and put the .class I want through a decompiler. But, after modifying the code, I can't re-compile it. The javac compiler just gives me a bunch of errors, mostly because it doesn't recognize the references to variables and methods that are defined in different classes of the program.
How can I change a couple lines of code in a Java program? Am I on the right track with my current approach (decompile→edit→recompile)?
SOLUTION: I had to include the classpath of the jar. javac -cp "[PATH TO JAR]:lib/*" [PATH TO JAVA FILE]
This question already has answers here:
Why is a .class file not human readable? [closed]
(5 answers)
Closed 7 years ago.
I open this file with ANSIC code,so how can I solve this problem?
That is not Java source code.
.class files are compiled Java binary class files.
.java files have the source code.
If you are looking for the source code of the Java compiler (javac), you can get that from OpenJDK. But it's a big and complex project.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Why do we use rt.jar in a java project?
I am very confused to knowing about rt.jar file.
What is the role
of rt.jar file or use of rt.jar file
in java??
Thanks.
rt.jar contains all of the compiled class files for the base Java Runtime environment. You should not be messing with this jar file.
For MacOS it is called classes.jar and located under /System/Library/Frameworks/<java_version>/Classes . Same not messing with it rule applies there as well :).
http://javahowto.blogspot.com/2006/05/what-does-rtjar-stand-for-in.html
Your question is already answered here :
Why do we use rt.jar file in java project ?
Basically, rt.jar contains all of the
compiled class files for the base Java
Runtime ("rt") Environment. Normally,
javac should know the path to this
file
Also, a good link on what happens if we try to include our class file in rt.jar.
I'm trying to figure out what a Java applet's class file is doing under the hood. Opening it up with Notepad or Textpad just shows a bunch of gobbledy-gook.
Is there any way to wrangle it back into a somewhat-readable format so I can try to figure out what it's doing?
Environment == Windows w/ VS 2008 installed.
jd-gui is the best decompiler at the moment. it can handle newer features in Java, as compared to the getting-dusty JAD.
If you don't mind reading bytecode, javap should work fine. It's part of the standard JDK installation.
Usage: javap <options> <classes>...
where options include:
-c Disassemble the code
-classpath <pathlist> Specify where to find user class files
-extdirs <dirs> Override location of installed extensions
-help Print this usage message
-J<flag> Pass <flag> directly to the runtime system
-l Print line number and local variable tables
-public Show only public classes and members
-protected Show protected/public classes and members
-package Show package/protected/public classes
and members (default)
-private Show all classes and members
-s Print internal type signatures
-bootclasspath <pathlist> Override location of class files loaded
by the bootstrap class loader
-verbose Print stack size, number of locals and args for methods
If verifying, print reasons for failure
As pointed out by #MichaelMyers, use
javap -c <name of java class file>
to get the JVM assembly code. You may also redirect the output to a text file for better visibility.
javap -c <name of java class file> > decompiled.txt
You want a java decompiler, you can use the command line tool javap to do this. Also, Java Decompiler HOW-TO describes how you can decompile a class file.
you can also use the online java decompilers available. For e.g. http://www.javadecompilers.com
Using Jad to decompile it is probably your best option. Unless the code has been obfuscated, it will produce an okay result.
what you are looking for is a java de-compiler. I recommend JAD http://www.kpdus.com/jad.html It's free for non commercial use and gets the job done.
Note: this isn't going to make the code exactly the same as what was written. i.e. you're going to lose comments and possibly variable names, so it's going to be a little bit harder than just reading normal source code. If the developer is really secretive they will have obfuscated their code as well, making it even harder to read.
cpuguru, if your applet has been compiled with javac 1.3 (or less), your best option is to use Jad.
Unfortunately, the last JDK supported by JAD 1.5.8 (Apr 14, 2001) is JDK 1.3.
If your applet has been compiled with a more recent compiler, you could try JD-GUI : this decompiler is under development, nevertheless, it generates correct Java sources, most of time, for classes compiled with the JDKs 1.4, 1.5 or 1.6.
DarenW, thank you for your post. JD-GUI is not the best decompiler yet ... but I'm working on :)
jd-gui "http://code.google.com/p/innlab/downloads/detail?name=jd-gui-0.3.3.windows.zip&can=2&q=" is the best and user friendly option for decompiling .class file....
That's compiled code, you'll need to use a decompiler like JAD: http://www.kpdus.com/jad.html
You need to use a decompiler. Others have suggested JAD, there are other options, JAD is the best.
I'll echo the comments that you may lose a bit compared to the original source code. It is going to look especially funny if the code used generics, due to erasure.
JAD and/or JADclipse Eclipse plugin, for sure.
If the class file you want to look into is open source, you should not decompile it, but instead attach the source files directly into your IDE. that way, you can just view the code of some library class as if it were your own
As suggested you can use JAD to decompile it and view the files. To make it easier to read you can use the JADclipse plugin for eclipse to integrate JAD directly to eclipse or use DJ Java Decompiler which is much easier to use than command line JAD
JAD is an excellent option if you want readable Java code as a result. If you really want to dig into the internals of the .class file format though, you're going to want javap. It's bundled with the JDK and allows you to "decompile" the hexadecimal bytecode into readable ASCII. The language it produces is still bytecode (not anything like Java), but it's fairly readable and extremely instructive.
Also, if you really want to, you can open up any .class file in a hex editor and read the bytecode directly. The result is identical to using javap.
There is no need to decompile Applet.class. The public Java API classes sourcecode comes with the JDK (if you choose to install it), and is better readable than decompiled bytecode. You can find compressed in src.zip (located in your JDK installation folder).
CFR - another java decompiler is a great decompiler for modern Java written i Java 6.