I recently lost my netbeans project folder of the project that I was working on at the time. However somewhere on a server here at the company that I work at, I deployed it. So that means that I (hopefully) can still get hold of the .war file.
Is it possible to then 'unpack' this .war and get my .java source files back that I was working on at the time?
Thanks in advance!
If the .java sources aren't in the WAR (and they should not be), you'll have to take the additional step of decompiling them using a tool like JAD.
This is a good time to set up a version control system, like Subversion or Git or Mercurial, so this never happens to you again. Get into the habit of using source code management, even if you're the sole developer working on the project.
Short answer: No.
Slightly longer answer: Look for Java decompilers, but they won't give you your Netbeans project folder.
You only get *.class files from your war (rename war to zip and use a decompression tool).
Then you could decompile them.
See this related question for some suggestions.
Suppose if you had exported the source files while creating the war, you can get it. Else, JAD is your only hope that too cannot fully rely on it.
It is possible to unzip the war file where you will get only class files and other property files. Then use Java decompiler to see source code and it works really well (not recommended).
Also you can change the property files without JD and all you need to do just change the property files and zip to war file again.It will work.
But I would recommend you to maintain source code in SVN or TFS or multiple copies with version numbers in local system at any point of time.
In Eclipse, you can Import your War, it will create a new Project and set the resources in the project structure. IF your war holds the source java files, the project will cointain your sources. IF not, the packages will be empty and you will have to manually decompile your classes from bytecode to java files, using jad or another decompiler.
Related
all. I am cracking a java software, it's a jar package. I want to decompile it and load its source to Eclipse, so I can analyze it. My Environment is Windows.
I used Java Decompiler to get the source zip from the jar package. Because the jar file is obfuscated, the zip file contains many files like a.java, A.java, Km.java, km.java... in the same folder (or package in java). Zip supports case-sensitive, but Windows does not. When I load the zip to a Eclipse project, the "no-matter-case-same" files get replaced (such as A.java is replaced by a.java), because Eclipse works on the Windows file system.
I don't want to change to linux, I hope there's a Windows solution?
First, it is very, very bad to crack software. So, you are a bad guy.
Second, I'd suggest you to try to run from zip. Configure your project to be dependent on your jar file, store decompiled sources in jar file too and add this jar as a source attachment. This should work.
But better solution is just leave windows ASAP and never return to it.
This maybe a noob question but please help me.
I found a library called Graphview for android and I would like to customize a bit and use it in my project. I know .jar is a zip file so after I extracted it I saw 2 folders, one contains some .class files and .java files, My question is, do I just need to change the codes I want in .java files? How about those .class files? And How do I put all the changed files back to recreate a new .jar file so I can use it in my project?
Here is the library from Github :https://github.com/jjoe64/GraphView/downloads
I would
fork the original git library.
modify it.
build it.
consider providing your improvement to the original build.
I wouldn't try hacking the existing library even though you can do this if you really have to (because you have no access to the original build)
You can just clone the original project, make your changes there, and then jar the changed project.
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.
I have a java application hosted on tomcat, which has a directory structure like :
webapps/my_aapp/WEB-INF/CLASSES/SERVLETS/xyz.java
webapps/my_aapp/WEB-INF/CLASSES/SERVLETS/xyz.class
so that's how classes are referenced .
Now (I am new to eclipse), it generates a different directory strucutre, in which all .java files are outside the code and I don't know where class files are stored.
The result is that when I upload the files, and compile, I get errors like this:
javac -Xlint servlets/Ajax.java
warning: [path] bad path element "/usr/java/jdbc7.2dev-1.2.jar": no
such file or directory
warning: [path] bad path element
"/usr/java/mysql-connector-java-3.0.16-ga-bin.jar": no such
What's the best way to understand this java directory path issue? Better yet, how to synchronize this structure?
I want to keep my eclipse directory structure on tomcat.
Typically eclipse stores all class files under bin directory located under your project near src directory.
I personally like name classes more than bin, so I always change it when I am creating project or later using project properties (right click on project -> properties -> build class path.)
Check your disk, I believe your class files are there. Unless you are using some pluging that can change this behavior.
What kind of project are you using in eclipse? A WEB project? An ANT-build project? MAVEN build? The way it builds classes depends on it. There is not much that I can help you. Because you do not provide enough detailed information with your question, but I will try.
Anyway, you can configure your output dir to be web/WEB-INF/classes (which is not statndard and not recommended, but I am doing it in one old project ;D) if you have it configured as java project.
1. Right click on project,
2. Go to Java Build Path
3. go to source tab, select source folders and select output folder (in my project mypoject/web/WEB-INF/classes ).
4. If you want to run and debug on apache tomcat from withint eclipse using this configuration, you can use eclipse sysdeo tomcat plugin.
Other thing is: You have specified absolute links to libraries (I suppose looking at your error messages), please copy them to web/WEB-INF/lib and change links in project settings. (If you are using maven that you should learn maven, if you are using ant, than just rewrite the part thaht uses these libs). And check if you already has this libs in tomcat/shared or tomcat/lib classes.
Another way is to learn to work with standard way of creating web-projects in eclipse, and add a build and package tasks to your build process (whatever it is make, ant or maven). Then you should deploy your PACKAGED application (let it be *.jar).
My suggestion, please, read "Head First Servlets & JSP by Kathy Sierra, Bert Bates, Bryan Basham" this is great book. It has everything you should know about HTTP, JSP, servlets, tomcat, and web-application directory structure. It will make things much easier for you (at least it worked for me, it really helped me much to understand things, and it is great fun to read).
I'm trying to use an open source java library to visualize nodes and edges in a graph, but I'm completely lost.
I have a bunch of jar files in a folder. Clicking on some of the jar files makes java swing windows pop open with graphs displayed. Clicking other jar files does nothing.
If I figured that out, would I just stick the jar files in there with the other ones, or would that still not work?
And if I ever figure out how to use these files, does that mean that I have to include them if I transfer my java project to another computer? How would I go about doing that?
I believe if you put the jars in your classpath, you can import and use classes just like you would a standard library. Figuring out the classpath can be confusing, but you can just set it when you start your jvm. Your IDE may have options for it, too.
Most java problems are classpath problems.
Have you included those libraries in your classpath?
If you are using eclipse, you could
Project - > properties -> Java build path ->addJar.
And the Jar file should be placed in a directory inside your workspace (lib/ for example)
If you have to take your project to another computer, you could take these steps
Before doing anything, export your project (as a Jar file, for example).
Save it into your favorite drive (cd / usb drive/ diskette/ tape).
On "the other" computer, you can import this project into your workspace
In Eclipse, you need to add libraries to the project build path.
In general, you need to provide dependencies via the classpath mechanisms at compile time and runtime. The precise mechanisms vary, but, for example, if you used the javac compiler, you would provide your libraries on the command line:
javac -classpath C:\dir\lib1.jar;C:\dir\lib2.jar foo/MyClass.java
These dependencies would also be required to invoke the app:
java -classpath C:\dir\lib1.jar;C:\dir\lib2.jar;. foo.MyClass
This page gives some good info, though googling for the term "classpath" should provide alternative sources.
You use it by including it in the classpath of your java application, that way you can reference it from your code. Here is a starter document. The JDK 1.6 has some easier options (such as specifying multiple jar files as *.jar). It is definitely a little complicated, but it is very worth knowing.
You should have documentation for these Jars. Some sounds like examples, but one must be the core graph modelling and rendering Jar. Hopefully the examples have source included.
Just add that Jar to your project in Eclipse (e.g., in a /lib folder in your project, then add it to the build path) and use the documentation to use the code. You can also use Eclipse to look inside the Jar file.
Unless there is no alternative, it probably isn't worth using a load of third party code that isn't documented at least on the API level, and without any source examples definitely not.