An ANT script to sync local with a remote version - java

Please, excuse my complete lack of experience with ANT.
I am looking for a script that basically compares the modification date of every .class file in a given local build, with that of its corresponding copy in a remote directory (server or sth). If a local file has recently been modifed, it just replaces the remote .class file with the local one.
I know that there are a lot of scripts for building war files and redeploying the whole application, and this is clearly what I don't want. Going through that every time for just a few lines of code being changed doesn't make any sense
Even if you can't point out a whole script, please give me some directions to look at. I know that ANT is pretty powerful so something like that should be a piece of cake, for even a newbie to write, right ?

The copy task does exactly that.

Related

Clear some stuff from Nailgun cache (usage: Jython)

This is a bit technical, and follows on from Using Nailgun in Eclipse for Java and Jython.
I have found out how to get Nailgun to work OK in on a Windows OS in Eclipse, using Jython. And using the unittest module.
What is baffling is that sometimes I make a change to a .py file, and sometimes (not always), an older version of this file continues to be run. This can even persist when I close down the Nailgun server, close its window, and start it up again: an old version of a file is being run, which no longer exists.
This feels very much like a cache problem. My understanding is that Jython does not generate .class files usually (although sometimes it does if you import a module??).
But perhaps this is indeed what Nailgun is doing. I have done some searching on my C: drive to see whether this cache location might be easy to locate: no luck.
Essentially I need the ability to tell Nailgun, between app runs, to delete a given .class file from whatever cache arrangement it maintains.
Incidentally, it doesn't matter whether the CLASSPATH elements in question are stipulated in the server's "SET CLASSPATH=..." or using the "ng-cp" option in the ng command line (i.e. in the client).
If all else fails I shall probably have to look into the NG source for inspiration. Gulp.

How does a proper UpdateLauncher for java look like?

I was working on an update launcher for a java .jar application. I have several .jar-archives and a main.jar. My launcher adds/replaces the necessary jars when updating.
I am just not sure what criterias to look after. So I'll describe how the process works and you might tell me if I forgot something.
Load and compare version.xml file from ftp update server
Make a list of updated items with the help of both version.xml files
Check (to be sure) if those files which are still valid really do exist on hard drive (either add them to the list of items that needs to be downloaded...shouldn't happen anyway)
Create a list of files that needs to be downloaded (those items are on the server in a compressed form)
Download all needed files to /temp folder
Unpack all files to /temp/unpack
Move all unpacked files to /data folder (or where they belong to)
Update local version.xml
Check if all files match the actual version-file-list
I am really not sure if I forgot something? If some users mess around with files in /data my updater recognizes this and proposes a "repair-update" where all missing files are beeing redownloaded. But what about users messing around with version.xml? I should store that encrypted. Is it necessary to keep the downloaded version.xml from update server open so that noone can change while checking version and updating? Or am I worried too much about all that?
Does all this work out so far and is it secure enough to not creaty messy installations on a users pc after patch?
Do you intend to use the System Tray class from Java 1.6 to notify the user of the update? To me, it seems like something like this would involve implementing an OSGi updater (sorta like how Eclipse project does it in the IDE). Also, the JVisualVM.exe tool (that comes with JDK) is an excellent example of this sort of thing and maybe you could get ideas from that although I suspect its coded in C++.

Can jar files be decompiled to get original source?

I have a major problem that happened to me. I am writing a program that has taken me 3 months+ to make and today I accidentally deleted the source code.
I am working in NetBeans and I had just cleaned and built it, so I still have the working .jar file. The program was saved on a flash drive, not my computer, so the classes are not in the recycling bin.
Can anyone tell me about how I can go about getting my source code back?
Unless you explicitly packaged your source code in the JAR file, there's no way to get back the original source. You could try using a decompiler (like this) but that will hardly give you nice, readable code.
The best solution would be to stop using your computer right now. Then use a recovery tool to recover your deleted files. The more recently it was deleted, the higher the chance you'll get it back. There are lots of tools that can be used to do this (just Google it).
You can use a decompiler ( see How to decompile a whole Jar file? ) but you won't be getting "original" source back.

java: how to copy the currently executing file

I have a jar. I want the jar to be able to make a copy of itself while running. I understand windows may have problems with this. How would I do this, or am I over thinking it?
Edit: To explain a bit more....
I'm writing a repackagable firmware deployment system... http://code.google.com/p/heimdall-one-click/ The idea is that a ROM developer from XDA can make his own, then pack it up in a cross-platform deployable one-click packaging nearly as easily as it is to deploy the firmware.
My program takes alot of the work out by automating the tasks... I'm trying to automate packaging of the one-click deployable packaging system.... give the developers a form to fill out which will change the header information, then they select their firmware files to be deployed. I'm trying to keep it all in one jar.
As josh says, it would be nice if you tell why do you want to do this in order to help.
Answering only what have you post, copying the jar is just copying another file. There is the issue that it might be blocked by the OS (Windows); another issue is how do you locate it in the machine and if the user running the process has the permissions needed.
Once those two issues are solved, it is just a copy operation, the OS could not care less that if the order to copy comes from the process run from the file or from another one.
EDIT to asnwer changes in the first post.
As I told before, in the end copying a file is a OS issue. If you want to copy the current jar in Windows, then the jar must not be locked by other process so it becomes an OS question rather than a Java one.
Possible workarounds:
The faster (but dirtiest) is to launch a .bat that does a sleep of a few seconds and then does the copy. Immediately after launching it, your close your java app. If you need to continue doing things in Java, after copying the file, the .bat launches the java app again (with the appropiate parameters).
A variant of the previous is slightly sleazier... launch your java app from a .bat, and the first thing that .bat does is copying your jar to the PC temp directory. Be sure to document it well so your users do not get scared!
JNI library to unlock a file. There are several programs that (Unlocker) that try to unlock files; do not know to which point it is effective or how will it affect the JVM.
I believe you can use:
File file = new File(MyClass.class.getProtectionDomain().getCodeSource().getLocation().getPath());
to get a reference to the path to the .JAR file.
Then you just make a copy of it:
http://download.oracle.com/javase/tutorial/essential/io/copy.html
Your operating system might not allow this, but I think it should.

Windows Mobile: automatically copy files on reboot

I have a Java app that runs on a Windows mobile device. At startup the app talks to our server to see if any files need updating and downloads them if they do. If any of the files are dlls they need to be stored in a temp directory and the device is rebooted because they might be currently in use. When the app starts it reads an xml file that lists all of the temp files and where they need to go and copies them into place.
A new requirement has come up that involves also updating the JVM files as part of this process. Since the code that does the copying is run on the JVM there is no way to do it since the files will always be in use. So we are looking at writing something in native code to do this copying process.
Before we start, I was just wondering if anyone knew of an already existing application or technique that does this (someone suggested a registry entry that tells the device to copy files on startup for example). Basically the requirement is to read some sort of configuration file that details the location of the source file and the destination then performs the copy. Any ideas before I reinvent the wheel by writing an app myself?
If your target handsets are handheld barcode scanners (Symbol, Intermec, etc.) they already have a framework in place for this. I don't have all the details, but I know from previous projects that they have a "protected" memory location that allows application to essentially re-configure / copy themselves from hard boots and similar problems. It might be worth seeing if any of that would work on your existing targets.
The scanners use either Windows CE or Windows Mobile.
In the absence of another answer, I have written a simple app to do it and put it in the startup directory. Was pretty easy, just didn't want to reinvent the wheel.
You can also rename your running executable file by the running-application itself. After this you can copy the file into the directory and simply restart your application.

Categories