source in jar file visible [duplicate] - java

This question already has answers here:
Jar File - Prevent Access to Source Code
(10 answers)
Closed 7 years ago.
I wrote a Java program and compiled it to jar file to distribute as a library that others import into their Java program and use it. It is a kind of simple library. The problem is when one imports the jar file into Netbeans to use it in their program, the source code is fully visible. They can open the classes in the jar file and see all the source. Is Netbeans decompiling the source or how is this possible? Is there a way to prevent users from seeing the source in Netbeans or any other IDE?

Yes, it's likely that Netbeans comes preloaded with a decompiler plugin, the only thing you can do is obfuscate all the classes in your jar with a tool like ProGuard.
They will still be able to decompile your classes, but it will be way harder to understand what your code is actually doing (heavily dependant on the complexity of your code). Sadly, you can't simply prevent decompilation.

I found out that this happens when the jar is imported to projects on the same machine on which the jar itself is developed. I took the jar file to another PC and imported it to a project, and alas the code is not visible. It is confusing why it behaving like that. I expect it should not show the code no matter what. Thanks for the replies.

Related

How can I get my source code back after I exported on .JAR file and after that I erased the project from the Workspace? [duplicate]

This question already has answers here:
How to decompile a whole Jar file? [closed]
(8 answers)
Closed 4 years ago.
I exported a project from Eclipse and then I tried to run'it in my machine and I couldn't. I readed some articles and I realized that I exported the program on a wrong way, (I'm using Eclipse as mi IDE) Eclipse gives you the option to export the project whit the (Runnable.JAR) option and the (.JAR extension), both are different. I thought the right way It was .JAR extension, but It wasn't, I tried with another project the (Runnable.JAR) and It worked. but I erased my priory project from the workspace of Eclipse(the one the I imported with the .JAR extension),and I've tried to import the program with the .JAR extension and it works but it just appear the compiled file, I can't run it. How can I convert the (.JAR to Runnable.JAR) or at least use it?
From what I can tell the only options you have are to either attempt to recover the deleted workspace, decompile your code, or restart the project.
To decompile your code I suggest either using this, or this, both should do what you want, but I've always had good luck with the 2nd option. As long as you haven't obfuscated your code, this should work correctly.

How to make changes to a J2EE application on Glassfish server? [duplicate]

This question already has answers here:
How to decompile a whole Jar file? [closed]
(8 answers)
Closed 7 years ago.
I was asked to make a change to a Java app hosted on Glassfish 3.0. I do not have the source code. Will I be able to obtain the source code by decompiling it, make changes to it, and redeploy it with my changes? Would anyone be able to help?
This is going to depend on how your ear/war file was compiled, if it was compiled with the include source option your will be able to obtain the source code.You can import the ear/war file into your IDE(Eclipse/Netbeans).
Extending #ChristianMajuta 's clear answer, I must mention: most java application can be recompiled even if its source code wasn't compiled into its jar/war/ear. What you have to do:
extract the jar/war/ear , extract its components, etc, until you get a big directory containing the .class files.
Look for a java decompilator. It is a software which can decompile .class files to .java source code. Here you can't ask for a software recommendation, but on softwarecs.stackexchange.com it is allowed to do, and google is also your friend.
Decompile the classes to java with it.
Do you intentended modifications.
Compile this again (best if you import your decompiled code into a new eclipse/maven project).
There could be little problems, for example, decompiled java code removes all of the comments and its general lookup will be much worse, but it will work. Fortunately, java is a very easily decompilable language. Good luck!

How to make jar file without using any IDE [duplicate]

This question already has answers here:
Java creating .jar file
(5 answers)
Closed 8 years ago.
I decompile jar file using jd-gui app. I made some changes on it.
After that i try to compile main.java file which one include all packages & other java files.
Then it Shows classnotfound exception.
I need to it without using any IDE.
Please Help me.
Thanks in advance.
A JAR (http://en.wikipedia.org/wiki/JAR_%28file_format%29) file is a ZIP-compatible archive of your compiled classes and other binary resource.
Feel free to unpack/pack it or treat it the way you treat ZIP-archive, say using your favorite archiving tool, like 7zip.
You can even create a ZIP archive with the contents you wish your JAR to contain and simply change the file extension to .jar.
NOTE: in case you use compression for your ZIP-archive, because in that case your manifest often must be the first entry in the archive.

How do I access and open a .class file [duplicate]

This question already has answers here:
How can I open Java .class files in a human-readable way?
(17 answers)
Closed 9 years ago.
How can I open a .class file in Windows 7? I am getting a message saying that I can't see the file and that I have to choose a program to open it or look online for one. Is there any website, explanation, or download that will allow me to access ANY .class file I have extracted or have saved in my Documents?
Are you trying to decompile the .class file and view the source code? You can use Java Decompiler. It has a standalone GUI and also plugin for Eclipse/IntelliJ.
Is there any website, explanation, or download that will allow me to access ANY .class file I have extracted or have saved in my Documents?
It depends what you mean by "access" or "open". It also depends what you mean by extracting ... and what you extracted them from.
If you are trying to run the class files, then the standard way to run a Java application is to use the java command, as documented on the Oracle website. For example: http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html. But how you use it depends on the nature of the thing that you downloaded and / or extracted. (Some ".class" files are not applications. Some ".class" files are designed to be run without extracting them from their JAR file container.)
If you are trying to look at the code in the class files, you could use the javap command to disassemble it. Or you could use a third-party tool to decompile it. But unless you have a clue as to what you are doing, this is not likely to help much. And since I can't really guess what you are trying to achieve, I can't offer you any useful references.
If you are trying to do something else, you'll need to explain what it is.
Either way, you need a Java installation on your machine before you can do anything.
You can use the javap command to view the disassembled class file. It is included in the JDK.

Adding a .dll file to a jar [duplicate]

This question already has answers here:
How to make a JAR file that includes DLL files?
(2 answers)
Closed 9 years ago.
I have a third party library that comes with .dll files that I need in order to run my java jar file. How can I include them in my jar file when I deploy my application? (I am using JSmooth to create an exe file - if that helps anything)
NOTE: I have looked at this stackoverflow question, but there's only one answer there, and I don't think it will work for me.
Thanks so much!
this has come up before. the short answer is that you cant - the dll has to be accessible to the underline OS and so cannot be inside the jar.
it can, however, be unpacked from within the jar to somewhere in the PATH before you call loadLobrary ....
look here : How to make a JAR file that includes DLL files?

Categories

Resources