How can I make it so Eclipse automatically updates my code in a window as I edit it? - java

How can I make it so Eclipse automatically updates my code in a window as I edit it? I've seen the feature before in youtube videos but I cannot find it. For example : I change a JApplet rectangle width from 20 to 10, I want to see it update immediately.

I've seen Notch do this on development videos (Minecraft), it is awesome but I don't know exactly how he does it.
-- EDIT --
This has been bugging me so I went and googled "how does notch code" and found this on a blog page https://gun.io/blog/what-i-learned-from-watching-notch-code/. It doesn't say exactly how it was done but gives a good hint (HotSwap) and makes it seem like he set it up himself without external software. Here's the most relevant section:
Incredibly Fast Testing
He began by building the engine, and to do this he used the ‘HotSwap’ functionality of the Java JVM 1.4.2, which continuously updates the running code when it detects that a class has changed.
When building the engine, Notch wrote a function which would continuously pan the camera around and clip through the walls and keep the view on top, so he could make changes to the code and see the effects they made in real time. I’m used to testing by writing a function, building it, installing it on the device I’m testing on, and then seeing the result, which can take up to a minute at a time, so it’s easy to see how HotSwapping could save a lot of development time.
--- ORIGINAL POST CONTINUED ---
I get a similar effect by using groovysh though, works smoothly and can use all your java classes as is.
What I'll usually do is write all my code in java, then go and fire up "Groovysh" where it will give you a little window to enter commands (You may have to ensure the classpath works correctly outside of eclipse). I can then "new" any of my classes and call methods on them one line at a time. When you do myFrame.setSize([100,100]) you will see it change immediately.
A good test is to just run groovysh and type something like:
import javax.swing.*
f=new JFrame()
f.setVisible(true)
f.setSize(100,100)
or the groovier version:
f=new JFrame(visible:true, size:[100,100])
and you will see your frame resize on the screen. You can even drag it bigger and then do something like:
println f.getWidth()
to show your new width. It's fun to interact this way but it's more complicated if you want to actually change your class definition and see it pick up the change, I have no idea how Notch did that. I looked into it a little--it's possible he was using something like JRebel
It requires something special since you would have to dynamically reload the classfile into your running system on every save--something that should have serious classloader issues.
By the way there is also a way to get your Java program to throw out a little GroovyConsole which will allow you to inspect and modify all the variables in your running code (but again you can't replace definitions of existing classes).
Also see answer here:
Change a method at runtime via a hot swap mechanism

Related

Java3D - How to dispose?

I've got a Java class that creates a Java3D (1.5.2) Canvas3D, adds some things, rotate it a bit and then saves it as an image - without actually displaying the Canvas3D in a JFrame or similar. That part works fine, based on the Java3D print_canvas3d example.
Unfortunately, the whole thing seems to have troubles cleaning up, because I see two symptoms:
a) After the image is saved, the application should be finished, but it does not exit. Calling System.exit(0) does fix that, but since the class will be used in an application server later, that is not a solution.
b) After the first image is saved, trying to create a second one (by creating a new Canvas3D, etc.) blocks the whole application on GraphicsConfiguration.getDevice() (and, if that is worked around by storing the Device in a static member, on similar places).
So, somehow the cleanup of the Java3D code seems to lack something very important. Unfortunately I can't seem to be able to find that...
I tried the solution given [here], tried to SimpleUniverse.cleanUp, SimpleUniverse.getViewer.getView.attachViewPlatform(null) and other stuff, but nothing seems to change it. The only workaround I found is to place the code inside daemon threads and save the whole Canvas3D part in a static variable, but honestly, that looks more like a mess and not a solution. Unfortunately, I don't have the time left to rewrite the whole thing in JOGL or similar and I also can't simply create an external application to write the image and exit for each call... So I need to know how to do it correctly.
My question is simple: How do I clean up a Java3D application correctly without System.exiting it?
Regards,
Flo

Swing Works different on different Platform

I have made a Screen Recorder using Java Swing and Xuggler 5.4. I have developed it in Windows 8 64 bit. It's working excellent for Windows. But at client side on Linux's environment , nothing is working. I have searched thoroughly but not getting any solutions. I have checked this thread , but it didn't work for me.
Then I tried to create simple Transparent window in Linux but it's also not working. I was not able to click through the Resizeable Panel. I have used the same JRE version (1.7) for both. Have I miss understood Java's Cross Platform Support as far as Swing is concerned?
Please Give Me Some Advice...
I have always found logging to be the best debugging tool at your disposal! Many a times, java debuggers take you into APIs where you need not go every time. Logging values of your variables, and generic 'I have reached till this point' statements make life a lot easier.
So, I suppose you have ample logging done in your code. That could give you clues on what's happening on your client's system.
Are the right environment variables set? Are they pointing to the correct Java versions you need.
If there are some specific Screen capturing requirements(plugins / modules / API) your code has, are they available on the Linux m/c?
Like #MadProgrammer said, in the end, Java has to talk with the native graphics APIs to render your screen.
I would try to debug it in this way -
Check whether my main screen loads or no(by disabling the screen capture functions for a while).
if not, dig deeper.
Check whether all necessary components for capturing screen(audio and video) are available.
Check whether the code is being run with appropriate permissions to control the h/w devices you may need.

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.

java applet using Next-generation plug-in

I have a web application (struts 1.3, Weblogic 10.3.0, Toplink, Oracle) that has a Java applet which isn’t working in the browser (IE7/8) when the Next-Generation Plug-in setting is enabled in the Java control panel but works fine when it’s disabled. The trouble is that this setting is set to disappear in an upcoming Java release meaning that my users would have to keep using Java 1.6_xx on their workstations as they are currently. I have little influence over which version they use because they are all governed by their local IT departments across the country. So, either I have to find a simple fix to allow the Next-Generation setting to work, or we have to look at replacing/rewriting the applet with something else (but would be a last resort due to funding constraints), most likely something AJAX-friendly so as to avoid the need for a plugin. This application is quite old, written around 2001 before AJAX was really around.
The main window has a left, right, and top frame (JSP’s), as well as a center frame which is where the applet is. The applet has a main content area in the middle and a lower panel at the bottom which has some buttons. The buttons tell the content area (which is basically a treegrid) what to do (Save, Copy, change status, etc ). When I press one of the buttons the entire window (surrounding frames plus the applet itself) repeat inside the area where the applet is. It’s like a kaleidoscope or like a repeating fractal pattern kind of thing, or like when you take a picture of yourself in the mirror and you see the room repeated over and over in the mirror. In this case it repeats for each button press and the repeated set gets smaller each time. Weird!!
So, based on my research, the Java Next-Generation plugin works differently by allowing more than one process or thread whereas the classic plugin only uses a single thread. So my suspicion is that a new process is being spawned for each button press. I tried using the “separate_jvm” applet parameter but it made no difference whether it was set to true or false. I don’t see any other applet parameters which seem to be relevant.
Another idea I had is that maybe it’s something to do with the JSP frameset, maybe something like “target=_top” needs to be added somewhere…but I’m not sure how this relates to applet threads if at all.
Anyone have any suggestions, ideas or experiences that might help?
you can use velocity to handle these type of problem and it will also help you for future enhancement also.
The problem is not related to version of IE but rather to version of Java. Below excerpt from letter of certificate provider (they took it from some forum, so direct link to source cannot be provided):
For JDK version higher than 1.6.0 and below 1.6_15, you can just
clear all kinds of cache in web browser, java console and java control
panel. Then it should works fine!
For JDK version between 1.6_15 and 1.6_30, you should disable the "next-generation java" option in java control panel.
For JDK version higher than 1.6_30, you should turn on "next-generation java" option in java control panel.

Getting a clue at / debug a huge Java Swing App I've inherited

I've been given the task to implement a new end-user functionality into a Java/Swing application. The task to implement is relatively easy and straightforward. What is cumbersome is the existing app to be modified.
It comprises dozens of classes which often break the 2000 lines barrer and sometimes reach 10000 lines.
Documentation is non existent and it is unfeasible to read all the source code to get the big picture of it.
The app itself is basically a GUI tool to draw diagrams (e.g. flowcharts) and is open-source (I can post the link to the source code if it helps).
So far I've managed to import the source code into an Eclipse project and use the SwingExplorer plugin to identify some of the GUI components.
The most 'interesting' part of the app is the canvas onto which the diagram is drawn. It is implemented as a single class (about 9700 lines long) that inherits from JComponent.
The parts of the displayed diagram can't be selected in SwingExplorer: the whole canvas is only identified as a single instance of the aforementioned class.
I hence guess that this huge single class is taking care of all the user interactions and AWT drawing operations for the diagram and returning just some kind of image buffer to display (but this is a huge guess).
My modification involves doing computation on the diagram as it is being drawn on the canvas. Therefore it is going to be a new class which will receive and process events broadcast during the creation of specific elements of the diagram, and then do some computation on them.
My main problem is: how to debug the event flow? How can I follow the flow of execution when drawing a diagram and see which events are generated, processed and also get an idea of where in memory the objects being drawn reside?
I know this question might seem too generic, but I'm really clueless and looking for a starting point.
Thanks in advance only for taking the time to read through ;)
Regards,
Marco
In NetBeans, I use File > New Project > Java Project with Existing Sources to allow easy navigation. Most IDEs have a similar feature.
Use Run > Generate Javadoc; even without comments, the Overview, Index, Use and Tree links may be useful.
Set breakpoints in the debugger and use Window > Debugging > Call Stack to answer question like, "How did I get here.
Run the code in the integrated Profile > Profile Project mode to see principle execution threads.

Categories

Resources