How to debug JavaFX - java

I've just started working with javafx, it seems cool and NetBeans seems much more fun than Eclipse but I find it impossible to debug my application. I've added breakpoints, and I pressed the debug button, I see the debugger is registered to some port but it doesn't cause the application to start.
When I run the application and attach a debugger nothing seems to happen. This is extremely annoying since I am using an external library I've added to my project, and I can't edit its content (since I am getting 'java file cannot be locked as it is read only').
I am very new to java and especially javafx, thank you for your help I sure need it:)

First off, I'd start with downloading the latest version of NetBeans (6.7.1 as of today). Second, NetBeans will let you put breakpoints in places that don't make sense for the language. You're best off putting breakpoints in a function like the run() function and stepping from there.
One more thing: make sure you have your JavaFX project set as the main project if you use that Debug button since I believe that it acts on your main project only.

Related

How to debug Java code in IDE (Eclipse, Spring Tool Suite) like Visual Studio?

First of all, I know my question is not a good question, I should say sorry for my this question, but this question confused me for a long time.
.Net/Visual Studio: I am coming from a .Net background. When I develop a project, I and my team are using the Visual Studio. When I debug the server side code (C# class code), it is very convenient since I use Visual Studio. I set the breakpoint, then I hover my mouse above the code, I can see what is the value of a variable or array values of a variable, so I can quickly know what is the value of a variable.
Java/Eclipse/Spring Tool Suite: When I was a student, all my courses are using Java with Eclipse, including course assignment and projects, and I found it was not convenient for debugging. Because I need to go to a debug mode, then I need to see a separate Windows within Eclipse, which shows the value of a variable in each row, this is not very efficient way to debug compared to debug in Visual Studio.
Now, I am going to develop the project using Java. This project is based on Spring framework. Then I found many people are using Spring Tool Suite, so I am going to use this IDE to develop my project.
My question is: Can we debug Java in an IDE like we debug in Visual Studio? What about debug code in Spring framework using Spring Tool Suite? Thanks.
Update:
All right, . I am testing this easy java program in Eclipse. I set the breakpoint, then I click "Run" -> "Debug", then I open a debug perspective. In the past, I only can see what is the value for variable a and b in Red Circle 2, but now, look like recently, when I put my mouse on variable a and b in Red Circle 1, I can see its value immediately? If yes, when this feature added to Eclipse? I am quite sure we cannot do so in Eclipse in the past.
Once you are actually debugging an application, you can hover over a variable in an open editor for the selected stack frame in the Debug view and see the variable's value. This is a long available feature.
You can also drag a view, using its title bar, out of the main window to create a new window if you want. I don't think this is heavily used, and may not work correctly with multiple screens, but it's there.
You're drawing a line based on IDE settings. Most likely, you're running in debug mode in VS even though you don't explicitly say it. That being said, your question is basic; of course, you can debug Java like C#.
Yes, of course, you can debug java code in Eclipse. Set a break point to the line you want to debug and select an object/variable/whichever and inspect it or add to watch.

How on earth does he debug a running application like this, and more importantly, how can I?

"Debugception!"
You may notice that within the first 15 seconds of this YouTube video (from 1:01:01 to 1:01:16), Markus Persson (aka "Notch", creator of Minecraft) has somehow managed to save/update an application and attach a debugger to it while it was already under the process of being debugged, supposedly all with a simple keyboard shortcut. The previously coded application somehow magically became the newly edited one, and seemingly without relaunching it or spawning a new process... It's possible that this is just some form of locally remote debugging, but something about it just doesn't seem quite right.
I've spent several days Googling and asking around on how he was able to do this, yet to no avail. I've found no such option under Eclipse preferences, and whenever I try to save & debug an already running application, it simply launches a separate instance of the newly updated application, side-by-side with the older, outdated one.
Am I missing something? How was this possible?
How was he able to utilize such an astounding, powerful debugging feature?
Thanks in advance!
Update
Okay, so this appears to be a standard feature specific to Eclipse.
Coming from a background in NetBeans and Visual Studio, I'm astounded that this doesn't seem to exist elsewhere (or at least in NetBeans!)...
This is a built-in feature of Eclipse. If you edit a method while the program is running in debug mode, it will compile the new method, and replace the old method with the new version. If some thread was already running that method, it will jump back to the beginning (AFAIK; this might only happen when the program is paused).
You don't need to re-launch the program or set any special preferences. Just edit and save, and the magic will happen.
Eclipse can't always figure out how to merge your changes into the running program - usually if you changed anything outside a method body (including the method's parameters or return type). In this case, you will get a warning dialog, with the option to stop the program, restart the program or ignore the changes.

Strategies for debugging a runtime Java crash that runs correctly in NetBeans

Sorry in advance. This is a really vague question because I have no idea whatsoever what is going on. I have a Java Swing GUI desktop app that I wrote in NetBeans. While inside of NetBeans, the app works fine and passes all of the tests that I have thrown at it. I've been developing this app over the past several months, deploying it at various phases of its development.
Yesterday, I finished adding and testing some new functionality. I built the application and put it on another computer. I then went to run the program (outside of NetBeans) straight from the jar file. While in the new areas (JDialog boxes), the program crashes. Since I am not in an IDE, I have no feedback to see what is wrong.
The only thing that I can think of (and this is lame) is that I added some switch statements that switch on strings, which I know to new to 1.7. I was previously developing in 1.6. Otherwise, I can think of no reason that the program should work flawlessly inside the IDE, but crash outside of it.
Can anyone offer any suggestions for how I should approach this? I'm at a complete loss.
Thanks very much.
The next debugging step for you is reducing the size of your program until it doesn't crash, then seeing what change you made worked. That should either make the answer obvious or give you a good question to post on SO.
Your idea that it might have to do with switch statements tells you to try:
removing them
removing and compiling on JDK 6 and see if it works
Those are reasonable ways to reduce your program size to see if you can make it run.
I would start from collecting a crash dump data.
If you run the UI on windows you could use DrWatson
If you run the UI in Linux , By default the heap dump is created in a file called java_pidpid.hprof in the working directory of the VM. unless you specify the path yourself by adding this -XX:HeapDumpPath= option to your UI java options.

Play! framework. create a new view

I created a new project using the play console
now, by default I got in my views directory two files:
main.scala.html
index.scala.html
I want to add a new view file. I call it "forums.scala.html"
now, I know that in order to render a view you need to do this:
views.html.forums.render("Forums");
the problem is that the intellisense doesn't recognize "forums"
but index and main it does recognize.
I've noticed those files:
class_managed/views.html/index.class
class_managed/views.html/main.class
but there is no forums.class so I suspect this is the problem.
I tried to build the project, but it didn't help.
so, what is the solution?
thanks
Your new views are compiled to managed sources after next browser hit if you are using play run for starting Play in dev mode.
If you'll use play ~run it will try to compile it as soon at it will recognize change in the file.
Finally if you started your app in production mode ie. via play start you have to stop it with ctrl+c and run again. Anyway, developing application in production mode is just a bad idea :)
Depending on your IDE most probably you'll need to refresh file structure to allow it find freshly created managed sources.
right click on ther project and click refresh, that worked for me - found it in another thread.
Found the solution.
running "compile" command did the work.
I understood that intelliJ do it auto, so I will probably use it instead of eclipse.
cheers!
If you want to program in scala, my recommendation is to forget about intellisense. Eclipses scala-ide is quite buggy, dont know about netbeans. And because of nonstandard layout of play2 application, non std development tools (play console), it becames even more handy to use simple text redactor (like sublime or textmate) with good old open-folder-as-project feature.

IntelliJ productivity tips running tomcat

I'm developing using IntelliJ 11u on a spring mvc application using tomcat.
I tried the maven jetty plugin, but after a few builds I keep getting java permGen issues and then it just hangs. I was told this was because spring uses log4j and it has some sort of leaks?
Anyhow, I'm asking for tips to help fire up a server, tomcat, with my updated code so I can make quick updates and have tomcat reloaded.
Here are my current annoyances with tomcat:
Only code changes seem to get auto-reloaded, if I make changes to my view pages things don't get updated unless I redeploy. The maven jetty plugin seems to map to my view pages directly and I saw updates to my view pages instantly w/o it even redeploying.
if I have more than 1 thing running in intelliJ, like say I have a main program that I run, or a unit test, IntelliJ seems to re-order what gets run in the run drop down menu and also the shortcut keys get changed to the last thing I ran.
I use google chrome, for some reason when I start tomcat it brings firefox to the forefront and opens a new tab each and every time.
If someone can address any or all of the above issues that would be great as I hate this dance I have to go through just to update/redeploy my application. I wish it could just be a consitant method, using shortcuts or automatically without me having to close the tab created in firefox, and then minimizie it, or redploy for a simple view change etc.
You should configure IDEA to update classes and resources and enable a checkbox in the Run configuration to do it automatically on frame deactivation.
Browser can be changed in IDEA settings and you can disable opening browser at all in Tomcat Run/Debug configuration.
As for the Run panel tabs order, you can pin tabs using the tab right click menu, in this case they will remain in the Run or Debug panel in the order they were created.
Look at JRebel if you want an even more productive environment (It costs, but I find it is worth it). As you can see here, http://zeroturnaround.com/jrebel/features/, it increases the types of changes you can hot-swap (no waiting for a build). I am currently evaluating it myself and will probably pick up a full license.
BTW, if you develop in scala (it looks like you're not, but just in case) the plugin is free.

Categories

Resources