I am new to both java and eclipse, I have been trying to debug an android app on a device. It is a small project with a jar file reference. I read similar questions but they didn't help.
What I need is to be able to debug the source codes of the jar file so I attached the source codes ( which I obtained using a decompiler ) and I am able to go into source codes of the library so I thought I did that correctly. But I can not succeed in debugging into these source codes; in debug mode it skipps breakpoints (only the ones in the source files which are attached to jar file) and when I try to 'step into code' it goes to random lines skips lines when debugging.
I am using the latest versions of eclipse, android sdk and jdk. I don't know what causes this problem and I'd like to know.
Thanks in advance, I hope I explained sufficiently.
The problem is, that you can't decompile the class files to debug it. Because the lines of the decompiled files will differ to the original Java source code lines (imagine: the real source code has some comments and other things which will not be compiled into class files)!
So, if your Eclipse shows you the current debug line 42, then it only tells you, that the debugger will present you the 42th line of code in the class file. This won't match your decompiled java source file.
However, you could decompile the class files with the option add line numbers as comments. These line numbers in comments you can compare to the actual stacktrace line numbers. This could help you a little bit to imagine the issue.
edit: as Laurent B recommended, you will be able to realign the code with JD-Eclipse, see: http://mchr3k.github.io/jdeclipse-realign/
+1 for the comment! :)
edit2: You won't be able to decompile with line numbers if the class files are compiled with the flag -g:none:
-g:none
Do not generate any debugging information.
So if this is the case: try to find the original source code of your jar file!
Its shows that the source file and Jar is not same. Try to get the right version of Source.
A decompiler will not get the exact source code but will try to recreate it from the generated bytecode.
This is an entropic process so Decompile(Compile(Source)) will not output Source (you loose information) such as line number. That is why you will need the original source code. If you don't have it, you will have to use your immagination to be able to follow the code :)
EDIT : apparently some decompiler tools can do that for you as stated by bobbel.
see jdeclipse plugin.
Try debugging your code line by line by pressing F6
Decompiled source code sometimes acts like that. Unfortunately, the only solution for you is to stop debugging the jar and search the web for the source code and add it to your project.
Related
I followed the instructions in Create and install de-lomboked source jar in maven for delomboking my source code and including it in the jar. So now, in another project, I can access the delomboked source. The problem is that IntelliJ uses this source to display when I click on a stack trace and the line numbers are wrong. IntelliJ is using the line numbers from the compiled source and it doesn't match up exactly with the actual source.
Is there around this? If not, I'll have to go back to using the regular source code, instead of de-lomboked
I was doing my school project today when suddenly my java BlueJ crashed and both my current file and my backup file got deleted.
One of my most important classes(SignIn.java) got deleted(only the source code).
While executing, it still works as it is linked but i can't find the source code to make changes or print it. There is a file with #BACKUP which might help me.
Is there anyway i can retrieve it? I spent almost 6 hours on this class and it took a lot of work.
As you can see in their manual at page 42 the #backup file is always saved in the same directory so your #backup file should be gone.
If you versioned it with svn or alike in the Team menu you can get Project History.
Otherwise.... you can use some file recovery programs.
The most popular can search for source codes in many languages.
The advantage of this approach is that you will recover comments meanwhile you won't by decompiling.
If your source code is truly gone (non-recoverable) you can try to use a de-compiler against the .class file. Jad and FernFlower are two that I've used and work pretty well.
https://github.com/fesh0r/fernflower
http://www.javadecompilers.com/jad
I might be using the wrong term when talking about "sync" but that's the best way to descrie it I think. I'm trying to debug a project that I've been working on for a couple of days now but for some reason the .java class and the .class file aren't syncing (.class file isn't updating to any of the changes that I make to the .java class that I'm editing). Let me start from the beginning I guess, when I do add break points to my .java file (sometimes the breakpoints are skipped) that I'm debugging and run the debugger when the breakpoint is reached the .class file is opened in instead of the .java file.
I searched around and found the solution to that with the help of some topics on here, which was "Edit source lookup". So the part about .class opening instead of .java file instead was solved. The main problem now is when I do edit the .java file with anything and run the debugger it completely ignores my changes. For example, if I implement a System.out.println("Test: 1") before a breakpoint or even after it's not printing to the console. Another example is if I comment out a line of code and run the debugger, the debugger still executes that line of code that I just commented out.
I searched for some solutions but they didn't help much. Some things I've tried were but did'n work:
Why isn't Eclipse updating the classes?
1.) Make sure the Build automatically is checked
2.) Cleaning the project
3.) Refreshing the project, F5
4.) Go to Wwindows->Preferences->General->Workspace and making sure the first 2 checkboxes are checked.
5.) Saving
6.) Restarting ecslipse
If anyone knows how to maybe solve my propblem I will be indebted to you. By the way I'm using java 1.7
What you describe indicates problems in you project definition.
Make sure that your project (main runnable class) specifies correct dependencies - that it does not specify dependencies on other jar files but includes dependencies from your related projects
Okay, so my programming teacher sent me an app that I should look at and modify. I downloaded the APK file, and turned it into a source code following these instructions: how to extract code of apk file.
I have the java (src) files, the resources files, and the XML files. I have the Manifest file too.
I imported them successfully on eclipse, but now it has like 2000 errors.
I really don't know what to do. The apk works fine on my phone.
Why is it doing this?
If anyone needs the apk, I'll upload it.
If someone can be so generous to convert it into a working eclipse workspace for me, I'll be more than grateful.
You can never get the exact source code from the .apk file. The .apk file is generated from the compiled classes which doesnt have all information like actual variable names, actual method names. so you cannot retrieve back 100% original source code.
Basically everything will be obfuscated. so when obfuscated, multiple classes may have same name.
eg: two classes may have name 'a'. Hence the Errors in Eclipse.
As far I know re-compiling apk file will not give you exact results except the images and xml resources. Some free tools available that cannot provide 100% accurate code. here's a tutorial you can check How To Retrieve The Source Code From A Compiled Android .Apk
One of the problems I'm running into is that my jar files and my source files don't match.
I'd like to:
Be Notified when when source and binary don't match (I think Visual Studio can do something like this...)
Set break points not by line, but by function. For example, set a break point at the entry of function foo().
I use eclipse mainly; so Solutions for eclipse would be most appreciated, but any IDE (or command line debugger) will do.
Thanks!
When developing just use and link to .class files that are saved by your IDE.
If your project starts to grow to a point where it's really useful to link to a .jar you're better off treating the jar's as separate projects.
Go to Project tab in Eclipse and then
click clean: Project->Clean…
click build automatically: Project->Build automatically
Use method breakpoints instead of line breakpoints. They can be set to halt on entering/exiting a method. You get them by double clicking the left editor side in a line containing a method declaration.
The debug information is limited to line numbers in the source file... I do agree that having a warning that the lines are wrong would be nice, but that would require more meta data in the jar than I think is available...
You might want to consider addressing the challenge with a change in your build process. This isn't exactly answering your question, but hopefully it will give you a strategy that will address the underlying problem.
When you generate the jar for deployment, also generate a jar with the binary AND source. For investigating the source code of a stack trace on the live server, set up a separate project in eclipse and have the binary+source jar be on the classpath. You may have to explicitly set the source code location back to the same jar (though I think Eclipse will just do this automatically).
Then you just have to add copying of the binary+source jar into the appropriate location in your workspace as you do your deployments (preferably with a deployment script).
If it's your server, you may want to even consider deploying the binary+source jar to the live server - that way you will always be able to get at the source.