How Hot Code Swapping Works - java

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

Related

How do you implement a programming environment in a workplace?

There are currently no development tools in the environment I work in. I am the only developer in the working environment. What are guidelines in implementing a programming/development working environment? (Example, what do I need to do, in order for me to create internal java applications, which may include tools, licenses, etc.)
As you are the only developer in your environment, there are a few things that are fortunate. You tagged this question with Java, so I will assume you want to work with this language.
Java itself, if not already installed. You can find Java at their website, and download the latest version on it on your machine. This will allow you to launch your Java applications outside the IDE (next point). To check if you have installed it, it is usually under your Program Files folder, most often: C:/Program Files/Java.
An IDE (Integrated development environment). There are a lot of them, but the most famous might be Eclipse. It often comes with an embedded Java version with it.
And that's it. Only the IDE would work pretty well. In pure theory, you could even do it with Java only and its compiler, but pretty much every Java developer uses an IDE. Licencing is an internal thing that you will need to implement.
By the way, I will let you read this, and flag it in five minutes. It should not be there. You should try Programmers' Stack platform for this kind of topic, which is not related to pure programming.

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/.

Usage of javaagent with Android

I've recently became interested in DBC methodology. As Java is my "native" language I've looked at cofoja and more recently java-on-contracts. I mainly create Android software, so naturally I'd like to be able to use contracts on my phone.
Both projects require the usage of something similar to
java -javaagent:path/to/cofoja-<version>.jar <someclass>
as JVM parameter. Is it possible to use this JVM parameter to launch apk on phone? Does dalvik even support this kind of parameters?
How could I even pass this parameter to start an application? I don't have a clue on how to start. Maybe through an ant script?
Closest thing to javaagent on android is instrumentation:
http://developer.android.com/reference/android/app/Instrumentation.html
but I doubt cofoja wil support this out of the box. I think it would be possible to implement this but not sure whether such project already started
And here is project goung roughly in direction desired by you:
http://code.google.com/p/droidbox/

spring insight with org.codehaus.paranamer

I have a java spring GWT web application. I need to use a profiler to view why is a certain function that slow (on server)... After some searching, seems that insight is a good way... tried it and it works... what I did is create a tc server instance (developer edition) with insight and add the project to it. It works.
The problem here is that I use maven plugin "org.codehaus.paranamer", that is a plugin that I use to get function paramater names... It works post-compilation to add a special private field in the class that holds the parameters names.
This is a problem with insight since it seems that it modifies the code too and that it works on the source code not the compiled version in the target folder.
What I can do to make this work? FYI, all I need is profile the app.. not necessarily with insight....
Edit:
I ended up using visualvm... It can help with profiling the app on the cpu level and the memory level... That is the way I can use the common remote profiling mechanism jerry was talking about.
For profile of JAVA apps(including tomcat instances), I strongly recommend the TPTP(Eclipse Test & Performance Tools Platform). You can read a lot here:
http://www.eclipse.org/articles/Article-TPTP-Profiling-Tool/tptpProfilingArticle.html
Especially for TPTP working with tomcat instance:
http://www.deepakgaikwad.net/index.php/2009/02/10/tutorialprofiling-with-tptp-and-tomcat.html
Some of the information in the above article may be outdated, but main workflow is the same.
For commercial profilers, I will recommend yourkit profiler: http://www.yourkit.com/
I don't know if there is a trial edition available now, but years ago, this profile is more user friendly than TPTP.

How to make a browser based IDE to code in the cloud?

I have read a bit about cloud and browser based IDE's.
I am planning to make a Java based bare bones IDE by integrating a compiler to code in the cloud. This is for educational purpose as I am just determined to learn to develop cloud based IDE.
I want it to be something like eclipse Orion but i want it to allow for coding in java. It should allow users to code, compile and run java programs by directly writing .java files and not by converting the .js files into java files.
Can someone please suggest me an existing cloud that I should use for this. And also, I am just a beginner and I have no clue about how to proceed and the articles that I am required to read.
Please do let me know what I should begin with and the cloud that suits my needs the best.
Thank you very much in advance.
You should look at projects like Mozilla SkyWriter, which implement the bare bones editing functionality
(There have been a lot of change lately. There seems to have been migrated to Ace)
You can use Codenvy and put your code on a Git repository. Then, you could build automatically once you have done the push using a CI tool like Jenkins. Now, I have an environment in which I use a Jenkins instance as a Service and also a runtime environment so I can get a continuous deployment pipeline. This video will show you, in a graphical way, what I am talking about.
Koding provides you with a full Ubuntu machine, with root, so it's able to run and do what you want, programming wise.
The reason i'm suggesting Koding though, is that they have a Framework to develop your IDE for the Koding VMs themselves.
The logic here, is that making IDEs is challenging, but the biggest challenges is ensuring security between your IDE users. Using another VM platform would mean that you don't have to manage the security of your VM, and focus entirely on your IDE.
Let me know what you think :)
For virtual/cloud hosting try one of the following:
Rackspace
VPS Farm
I like vpsfarm because it is cheap and pretty bare bones.
For the IDE itself, I would first create a webapp that can upload and compile and run arbitrary java code, without adding libraries or J2EE. That alone will be a good undertaking for one dev.

Categories