I have a major problem that happened to me. I am writing a program that has taken me 3 months+ to make and today I accidentally deleted the source code.
I am working in NetBeans and I had just cleaned and built it, so I still have the working .jar file. The program was saved on a flash drive, not my computer, so the classes are not in the recycling bin.
Can anyone tell me about how I can go about getting my source code back?
Unless you explicitly packaged your source code in the JAR file, there's no way to get back the original source. You could try using a decompiler (like this) but that will hardly give you nice, readable code.
The best solution would be to stop using your computer right now. Then use a recovery tool to recover your deleted files. The more recently it was deleted, the higher the chance you'll get it back. There are lots of tools that can be used to do this (just Google it).
You can use a decompiler ( see How to decompile a whole Jar file? ) but you won't be getting "original" source back.
Related
I'm editing the bytecode in one of my old projects to fix a bug, because I no longer have the source code. Everything was fine and dandy until I went to re-insert the modified class.
The code was obfuscated when we released it, so I have two files: hl.class and hL.class. hl.class is the one I'm re-inserting, but using WinRAR causes hl.class to just replace hL.class and delete the old hl.class! It's annoying and I can't figure out how to just re-insert the damn file.
Does anyone have any insight? Are there programs that won't be such a diva about this?
Thanks!
In short, use a better zip tool. I'm assuming that you're stuck on Windows, with its case insensitive file system. Even if none of the GUI zip tools work, you can always open up a Python command prompt, which allows programmatic access to zip files, including specifying the exact filename of the content to be inserted.
If you have access to a Linux or Mac machine, it's much simpler. Just edit the file as normal and put it back into the zip. Since hl.class and hL.class have different filenames, there won't be any problem.
P.S. One other option - the Krakatau assembler has an option to output classfiles directly to a jar, allowing you to correctly handle case sensitive filenames even on Windows. Krakatau is also a great tool in general for low level modification of classfiles. (Disclosure, I wrote it)
I actually found the solution the day I posted this, I'm sorry I forgot to respond and post it!
If you're on a Windows machine like me, I found a handy program called muCommander that's a cross platform file manager that isn't case sensitive. I managed to get the file in with it.
There's also some registry values you can tweak to get Windows to recognize case sensitive files, but I'd recommend the program I posted above to keep it simpler.
Thanks everyone!
I’m coding my first java Desktop application using eclipse and I’m having difficulty deploying it. My project uses JavaFX2 and the e(fx)clipse plugin, the latter is in charge of generating the build.xml file.
ABOUT THE APP
The app, amongst other things, provides an interface where the user can create categories and associate these with labels. All modifications are saved within a single file (the data is stored as a serialized object.) and are supposed to be loaded automatically when the app is reopened.
THE PROBLEM
When build as an executable jar using a .xml file (Ant), the project runs fine within the folder where it gets created. I can run my application, modify data, and save everything once I’m done. When I reopen the app everything gets loaded as it should.
However, if I copy the folder elsewhere, I can no longer save any data. Everything else seems to work; the app will even load the data that was saved when it was in its original directory. I assume that this means that the app can still see the data file, but can no longer write to it.
WHAT IVE TRIED
I’ve read that warping the .jar around an installer may fix the issue; however, one of the goals for the app was to make it as portable as possible. Meaning that it should be possible to move it around from one directory/computer to another, ideally in a manner that is cross-platform friendly, without the need of installing it.
I’ve tried various things to get it to work. I’ve shifted the whole project to Netbeans (to produce a different build), I’ve modified the save/load method file path to make sure the right document is targeted, I’ve tweaked the .xml file the best I could, and I even tried to build the project using the javafxpackager. No matter what I do, when the build works, I get the same results.
Right now, I’m thinking that there may still be something wrong with the .xml file but I’ve got a hard time understanding how to modify it. Perhaps the problem is somehow caused by the way the data gets serialized. I know that at one point when I moved things around within my project, both the save and load methods could no longer interact with the data.
What I find strange is that when the project is moved the load method still works. If the problem is caused by changing the file path, how come only the save method ceases to function?
APP FILES AND STRUCTURE
+src
-(Main.java)
+controller
-(misc.javas)
+modelData
-(Library.java) -->the object that is serialized
+modelLogic
-(misc.javas)
+view
-(misc.javas)
+files
-(library.data) -->the file where the serialized object is saved
+lib
-(empty.empty)
So, is their anything I can do to solve my problem?
Thanks in advance.
In the end, the problem was rather simple. When I was moving the app, I was always putting it on the desktop, which, in the case of my PC, sets by default all content as read-only (in relation to the app's privileges). Because of this, the app could not modify any files that were within folders on the desktop.
Therefore, all I had to do was to move the app to another directory, such as C:\randomFolder, and the problem was solved.
So, if anyone has a similar problem, moving the app elsewhere may be the solution. Alternatively, taking full ownership of the folder and its content can also work.
When possible, it is usually better to have the app ask its user for a specific location to save its data.
I recently created a project in Netbeans using VirtualBox on which i installed windows XP (Not activiated)
My Windows required me to activate and would not allow me access to my files on the computer before i activate it, i stupidly went and uninstalled XP and reinstalled it, thinking i'll have access to all the files from the JAR file i created
I want to know if theres any way i can use the class files of the project i created, to create new java files so that i can edit the code in netbeans ??
Please if anyone can shed some light on this topic, if its at all posible to gain access to the forms java content i created. Im new to programming and this is something above my knowledge (i hope this makes sense)
If not possible please let me know what an absolute idiot i am, so that i can start re creating the project from scratch ... Sigh, and thank you
A jar/class file is compiled bytecode that is not human-readable... but with Java it is easily converted back. Look into a program like JavaDecompiler.1 This is not my program but I use it and I find it workable for my needs.
1 If this is considered spam I'll gladly invalidate the link.
As a sidenote: You are lucky that its Java. In many other languages like C++ that would hardly be possible. The difference is that Java does not compile the source code to machine code. That step is hardly reversible since for example all variable names are lost. Try to understand a non-trivial piece of code without helpful variable names...
Java instead compiles the source code to byte code which then is interpreted by Java on runtime. That byte cold holds way more information about the original source code than machine code.
I tried to reimport my android project on eclipse to solve a problem but I accidently overwrote all my files in the project. All of them had been corrupted which means their size is now 0B...
I tried to use Local History but it's useless since my project is no longer in my workspace, same for .metadata.
I also tried to use Recuva (Software for recovering files) which see my files with their real size but when I try recover them, their size is always 0B...
I lost about 7 days of work and I don't really want to rewrite my code using Java Decompiler...
So my question is, is there any solution to recover that files ?
I wrote 200 lines of code and suddenly system restarted. I lost all code. But I recovered data from eclipse's local history. Right click on the file -->replace with-->previous from Local History
Eclipse has a local history, although by default it's set very low - one of my first tasks when setting up a new development machine is to up the values (in addition to my other version control)
If you do have a history you can right click on your class, and select compare with local history.
You could try decompiling with something like JD-GUI. It might not be as onerous as you think. Obfuscators exist for a reason.
It is not really programming question, but i had similar situation and "Mini Tool Power Data Recovery" tool helped me (it is paid tool, free version exists, but maybe you can search in this direction and find something open source). I tried some another tools then, but with no results.
I was working on an update launcher for a java .jar application. I have several .jar-archives and a main.jar. My launcher adds/replaces the necessary jars when updating.
I am just not sure what criterias to look after. So I'll describe how the process works and you might tell me if I forgot something.
Load and compare version.xml file from ftp update server
Make a list of updated items with the help of both version.xml files
Check (to be sure) if those files which are still valid really do exist on hard drive (either add them to the list of items that needs to be downloaded...shouldn't happen anyway)
Create a list of files that needs to be downloaded (those items are on the server in a compressed form)
Download all needed files to /temp folder
Unpack all files to /temp/unpack
Move all unpacked files to /data folder (or where they belong to)
Update local version.xml
Check if all files match the actual version-file-list
I am really not sure if I forgot something? If some users mess around with files in /data my updater recognizes this and proposes a "repair-update" where all missing files are beeing redownloaded. But what about users messing around with version.xml? I should store that encrypted. Is it necessary to keep the downloaded version.xml from update server open so that noone can change while checking version and updating? Or am I worried too much about all that?
Does all this work out so far and is it secure enough to not creaty messy installations on a users pc after patch?
Do you intend to use the System Tray class from Java 1.6 to notify the user of the update? To me, it seems like something like this would involve implementing an OSGi updater (sorta like how Eclipse project does it in the IDE). Also, the JVisualVM.exe tool (that comes with JDK) is an excellent example of this sort of thing and maybe you could get ideas from that although I suspect its coded in C++.