How to debug plugins? - java

I'm working on a project for class that involves me developing a plugin for an existing application. However, I struggle with GUI programming and the inability to use a debugger or print statements has made the process very not fun. Is there any way I can debug this thing other than trial and error?
The plugin (as well as the main program) are written in Java, and I'm using NetBeans. I'd prefer to stick with NetBeans but would be willing to move to a different IDE if necessary.

You should be able to use remote debugging as described here http://wiki.netbeans.org/FaqDebuggingRemote
This involves running the original JAR from the command line with the following parameters `"-Xrunjdwp:transport=dt_socket,server=y,address=8888,suspend=n"
This would then allow you to attach the Netbeans debugger to the running process.

Related

how do I get a preview of a java swing application without actually running it?

Is it possible to get a good preview of the java swing application without running it repeatedly in IntelliJ? Whenever I modify code I have to run it again and again so that it looks good.
It also generates a bunch of classes that I don't really need since I'm committing to a GitHub repository How do I do this?
I don't know about IntelliJ, but Eclipse has WindowBuilder, a visual designer and development tool that supports Swing. You can install it into a variety of Eclipse releases, I don't think it comes pre-installed in any of the Eclipse packages.
eclipse and NetBeans does have some WindowBuilder future
if you are using eclipse download this
and if you are using Netbeans it does provide a WindowBuilder itself so read this article

While in development in Xpages Libraries, changes are not picked up

I work with multiple XPages Libraries that contain all of our Java code outside Domino Designer. I'm using Eclipse Mars and have setup the Xpages SDK to make this work. Most of the Java code is called from Xpages (or managed bean inside a nsf). But everytime when I make a change in our Java code, the change is not picked up. I need to "restart task http" on my Domino development server everytime.
When I turn on debugging and change Java code, all changes are picked up immediately but it will crash my server when I change a return type or add a new function or move classes between packages.
Is there an easier way to develop in Java without restarting the HTTP task everytime I make change (or prevent those server crashes)?
When debugging from Eclipse, if you use the Stop option, it crashes the server. If you use Continue, it works fine.
In terms of hot-swapping code, there isn't a way currently. JRebel can be used with some servers, but I don't know of anyone who has got it working with Domino.
It's not specific to plugins though. The same is true of any shared Java code, presumably because it's compiled to byte code and cached. See this blog post where I had issues with SCXD http://www.intec.co.uk/single-copy-xpage-design-some-learning-and-why-its-not-for-me/. There are various tell http osgi commands including ones for bundles etc, but I haven't found one that successfully reload plugins. I think Cameron Gregor did some investigations as well, but also couldn't find a way. It's one of the issues I highlighted with OSGi development on Domino on my blog http://www.intec.co.uk/from-xpages-to-web-app-part-seven-osgi-application-development-introduction/.

How to deploy and run my java program on a server using IntelliJ?

I'm running a data mining program using IntelliJ on my computer, but I need to run the program on a server for its larger memory and faster CPU.
My current work flow is: Write code on laptop => push code to github => pull code from github on server => compile and debug. I found myself wasting a lot of time during the development.
Is there a way to get my code written and compiled locally on IntelliJ(or Eclipse) and pushed to server for running directly?
In general terms, what you need to do is:
Install the Intellij plugin associated with your application server.
Create a run configuration associated with your app.
Build/deploy/debug and refine.
The secret sauce is #2 and is what #Jagermeister is alluding to. From there you can do a plain IDE build, maven goals, ant tasks, or any external tool you care to configure.
The main thing you need to do is find the most efficient way to integrate your build workflow with Intellij. If you're using simple IDE builds (what Intellij unfortunately calls "Make"), Intellij has built-in facilities for deploying "exploded" artifacts (non-archived), which allows for extremely rapid debugging via "hot-swapping" of modified classes.
All of this is in the docs.

How Hot Code Swapping Works

I've been programming in Java, and I really enjoy the feature in Netbeans and other IDEs that allows you to make changes to your program while debugging without having to restart it. I am writing an application in Java which would benefit if I could update it on the fly without having to restart it. I had the idea to have a second jar that I could run when updated, which would be able to do the same thing that the IDE's do, but I have no clue how they swap the code. Can anyone enlighten me? Thank you!
IDE's such as Eclipse, when debugging use the JDI (Java debug interface). It is a collection of Java API's which allow you to create / attach onto external Java Virtual Machines. This can be used in conjunction with a Java Agent which can be used to re-define classes in the virtual machine. What Eclipse does during debug mode is create a new Virtual Machine with your code running in it. When you make an edit and re-compile; eclipse then tells the JVM to re-define the classes you have changed, by sending over the new byte-code.
You can read the JDI documentation, and take a look at the Java instrument class (which is used to configure a class-transformer) in particular. Here's a related question on setting up a JDI launcher (launch a new JVM).
I was actually learning about the same thing #work today. I found this article pretty helpful in understanding the workflow behind a few of the more complicated hotpush cases:
http://java.dzone.com/articles/5-jrebel-features-you-couldn%E2%80%99t

Can we debug Java programs with no main method?

We have a vast Documentum application which I have deployed in Tomcat. The code is being maintained and compiled in Eclipse IDE.
It is very hard to track where and what data is going through which code, I have a decompiler plugin to help with this task, but it does not work with most of my code as the classes are without a main method. These classes cannot be decompiled by the plugin.
Is there any method to overcome this? So that I can see the flow of data from JSP to backend class to repository, and vise versa.
Sure. You can either connect to tomcat using remote debugging (see here) or run tomcat into eclipse itself. You need appropriate plug-in for this but typically standard eclipse distributions for server side development already have one. Open Servers view, create new server, follow the wizard and you will be done in a minute.
JPDA is a java standard tool.
It is designed for use by debuggers in any environment on any java application.
For details you can look at
http://www.ibm.com/developerworks/opensource/library/os-eclipse-javadebug/index.html
http://www.ibm.com/developerworks/library/os-ecbug/
The 1st link gives a detailed view with screen shots of remote debugging using eclipse.

Categories