File with same case in JAR file on Windows - java

I'm editing the bytecode in one of my old projects to fix a bug, because I no longer have the source code. Everything was fine and dandy until I went to re-insert the modified class.
The code was obfuscated when we released it, so I have two files: hl.class and hL.class. hl.class is the one I'm re-inserting, but using WinRAR causes hl.class to just replace hL.class and delete the old hl.class! It's annoying and I can't figure out how to just re-insert the damn file.
Does anyone have any insight? Are there programs that won't be such a diva about this?
Thanks!

In short, use a better zip tool. I'm assuming that you're stuck on Windows, with its case insensitive file system. Even if none of the GUI zip tools work, you can always open up a Python command prompt, which allows programmatic access to zip files, including specifying the exact filename of the content to be inserted.
If you have access to a Linux or Mac machine, it's much simpler. Just edit the file as normal and put it back into the zip. Since hl.class and hL.class have different filenames, there won't be any problem.
P.S. One other option - the Krakatau assembler has an option to output classfiles directly to a jar, allowing you to correctly handle case sensitive filenames even on Windows. Krakatau is also a great tool in general for low level modification of classfiles. (Disclosure, I wrote it)

I actually found the solution the day I posted this, I'm sorry I forgot to respond and post it!
If you're on a Windows machine like me, I found a handy program called muCommander that's a cross platform file manager that isn't case sensitive. I managed to get the file in with it.
There's also some registry values you can tweak to get Windows to recognize case sensitive files, but I'd recommend the program I posted above to keep it simpler.
Thanks everyone!

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.

JNotify dosen't recognize Files changed by Linux System

I am using JNotify in one of my Projects on a linux system (arm7).
And it works great. If i change, rename, delete or create a File it throws an Interrupt.
But I would like to us JNotify to get informed if the Linux System change a File by itself.
I am using a BeagleBone (embeded Linux System). There is a file called value which contains the status of an InputPin (high, low). But if this file is changed by the system JNotify dosen't work... If I change the file by my self everything is ok...
Does anyone know why the change wasn't recognize in the first case.
Linux seems to use a special way to write the file... yet i dont't know how...
But need to interrupt my main loop if this file changes.
Or is there another solution?
Thanks
JNotify relies on events from the file system. for Linux it's using the inotify system call (which is actually what inspired it's name).
inotify only works for real file, the file you are described is a virtual file that does not exist on disk and is not a way to store information but rather an easy way to access system information and sometimes change it).
an alternative solution would be to create a sampling thread that will check the file, sleep, and check the file again.
since you only care about a specific file, this is pretty easy.
while it may feel too expensive, polling is actually very common when dealing directly with hardware.
since that file is actually not really a file, reading it would actually be faster than reading a file.

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

How to put java code into an application format?

I made a simple command-line based game in java, only two classes (using Eclipse). But I was wondering how I can make this into a usable application for anyone, without running it through eclipse (ie send it to someone who knows nothing about java but would still be able to play the game)? Thanks!
You want to create a runnable jar file.
Eclipse has an option for this in the "Export" menu. For more options, search for "executable jar file" here or on Google.
You want to make sure that you also include any jar files your code depends on as well (Eclipse can also do that for you).
Users will be able to start this by double-clicking on the file on most platforms. If you need better integration (such as a custom icon), you will need to bundle it up further into an OS-specific executable. But for starters, a simple runnable jar works fine.
send it to someone who knows nothing about java
You need to get them to at least install the Java runtime on their machine (if it is not already there).
Just to be clear, "command-line" and "knows nothing about java" are probably not going to work very well for you given that:
java is OS agnostic, therefore, if you send (presumably) a jar file to say...your grandma and she has a mac and you have a PC chances are her getting it to work is not going to be "out of the box easy" so to speak.
Left with this, I think you have a couple choices...first off, you do need to package your classes - a runnable jar will work fine. Aside from that, you will most likely have to build OS specific scripts (batch scripts for Windows, shell scripts for unix, etc.) and you will have to hand these out with your jar file. That being said, the intended user will still need to have java installed, and the batch scripts themselves are not likely to be trivial endeavors.
Your next option would be to use JNLP. However, I don't think JNLP has a command line mode, so you will likely have to simulate a console with something like a JTextArea.
As far as I see it, your last option it to use one of the many products (not sure if there are any free ones) that package java into native code. I think Exe4j is one such example - but, like I said, I am not sure if there are any free ones and I am not sure how hard they are to use.
Best of luck, and if you can't get your jar to work you should probably move that to its own question.

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.

Categories