jar file sometimes doesn't start from network share - java

We have a Spring Boot (v2) powered JavaFX application (v8). More user run it on Windows, from a network share, at the same time (with a batch inside java -jar command). Jar is created by Spring Boot Gradle plugin and runs on Oracle JRE 1.8.
It run properly for months but nowadays sometimes fails to start with error message Error: invalid or corrupted jar file. (Manifest file is correct.) It usually happens when:
A user locked its PC when the application runs. After another user logs in and tries to start the same jar. This happens only on that PC which runs the jar within the locked user session. It happened on multiple machine not on only one.
And we got a bug report: application threw a NoClassDefFoundError but the class is inside the jar. I think these errors have relation.
We release periodically after one or two weeks and the bug is occured in multiple versions.
I dug a lot to find a solution or a detailed description of this error, but I found nothing.
Do you have any idea?
P.S.: We use this code snippet to determine which version of jar is running:
String manifestPath = classPath.substring(0, classPath.indexOf("!") + 1) +
"/META-INF/MANIFEST.MF";
Manifest manifest;
manifest = new Manifest(new URL(manifestPath).openStream());
return "v" + manifest.getMainAttributes().getValue("Manifest-Version");
We started to use this code near the bug is reported. It runs only on startup. I see stream is not closed manually or a try-with-resource block. Can it cause this behavior? I think not because GC will dispose the stream with an undetermined delay and between two application startup is more hours are estimated. And it is not associated with the NoClassDefFoundError.

It is not running reliably, because this is a very un-safe and un-reliable way to run an application. Executable code should be locally on the machine executing it.
So if it has to be on a network drive for some reason then it should be copied to the server it is going to execute it and then executed there.
Since it almost sounds like you are doing some sort of build process here it would be a much better idea to use an actual build tool like Jenkins to do this.
On the log list of issues that can happen executing from a network share:
o More than one user could try executing it at the same time causing conflicts.
o Which ever file sharing protocol could be locking the file(s) while one looking at the file or has it selected in their network viewer
o Different users with different permissions will get different behaviors. If it is trying to look on the drive or config files, or write a log file(s), etc. some users permissions on that file share may not Have the needed access.
o Network file shares are inherently un-reliable causing the file to not be accessible randomly, or to be reported as corrupted randomly.
o Different users on different machines with different versions of the networking protocols will get different behaviors.
o Different share protocols handle the data integrity checking differently and will cause different results.
And this could keep going for quite a while. You get the idea.

Related

(Bad) lagg on auto complete in Eclipse

Basically when I auto complete on Eclipse (By pressing CTRL+Space) the program laggs for about 5 seconds. This is getting really annoying because I use the auto complete alot. How do I fix this?
The workspace I'm working on is located on a NAS with a 1Gbit/s connection. Could this be causing it?
Thanks.
Check if problem exists with local resources too
Create a local workspace and open it with same eclipse instance. Now create a simple java project by new project wizard at your local machine inside this workapce and try code completion there. If it's still slow go to Step 2.
(by the way - I wouldn't store workspace information on remote side, but always local)
Check proposal kinds
If it's not a network issue and the problem still exists on a simple local workplace with local sources you should inspect your proposal setup as shown in next picture.Maybe one of the proposal kinds is slowing down your IDE. You can experiment with turning off proposal kinds sequential to find the problematic one.
System requirements
If you got stil the problem after doing Step 1-2 maybe your system has not enough power/memory to provide eclipse (but normally not the reason - I am using eclipse at Linux on an old T61 notebook with 4 GB Ram + SSD and it works fine!)

Java Camel RouteBuilder picks up file before copying is complete

I am using Ubuntu (in case it will make a difference) and I am trying use Camel to send files to processor from one folder. But the problem is that when I am saving this file in the folder (takes about 5-10 seconds) Camel picks it up straight away.
To simulate the process I am using gedit with txt file with ~500k rows so it will take some time to save.
I have tried adding options:
from("file:src/Data/new/?readLock=changed&readLockMinAge=3m")
I have tried using
.filter(header("CamelFileLastModified").isGreaterThan(new Date(System.currentTimeMillis()-120000))) to give 2 minute delay.
Nothing seems to influence its behaviour, it picks it up straight away, throws an exception because of some checks while processing file and moves it to the Error folder.
I know there is an issue with FTP file transfers which I will have to face later on, but I can not even get it working on local file system.
Any help will be appreciated!
SOLVED
from("file:src/Data/new/?readLock=changed&readLockMinAge=3m")
Parameters actually work as they should. I was using Jetty to run the project and I should have done whole project clean/install after any amendments.
I had to amend parameters a bit to:
from("file:src/Data/new/?readLock=changed&readLockTimeout=65000&readLockMinAge=1m")
because it was complaining that readLockTimeout should be more than readLockCheckInterval + readLockMinAge.
Have a look into the documentation:
Avoid reading files currently being written by another application
Beware the JDK File IO API is a bit limited in detecting whether
another application is currently writing/copying a file. And the
implementation can be different depending on OS platform as well. This
could lead to that Camel thinks the file is not locked by another
process and start consuming it. Therefore you have to do you own
investigation what suites your environment. To help with this Camel
provides different readLock options and doneFileName option that you
can use. See also the section Consuming files from folders where
others drop files directly.
So I think the doneFileName option will solve your problem.

Preventing Java from creating new processes

I am setting up a little service to allow people to run temporary Minecraft servers on a spare box that's not being put to much use.
The .jar that will start up the Minecraft server will be uneditable, as in they can't upload a new .jar and run that in its place. However, the .jar will be the Bukkit Mod/Wrapper for Minecraft servers, which allows the loading of plugins that are in the form of .jars. What's stopping someone from creating their own plugin and using it to spawn more servers?
How can I prevent someone from using a server plugin to create another server process? I am already planning to make it so that each server will be ran under it's own user account, which wont be accessible to login from.
I'm not familiar with the Minecraft code base.
However you should look into running the code with a SecurityManager. This will enable you restrict many operations (such as being able to exec a new process).
Done correctly, this should enable you to completely lock down the loaded .jar file. It's possible that the Minecraft server does this for you already, it's a fairly obvious thing to want to restrict the activities of downloadable mods.
In linux there is a file called /etc/security/limits.conf.
Read this: http://linux.die.net/man/5/limits.conf.
nproc would limit the number of processes for the user/domain.

Mirth Running Old JAR File Code

This is really driving me crazy. No matter what I do, it seems that Mirth (1.8.2) is running an older version of my JAR file; I know because of various signs, like:
I can't call any functions
Information logged is not showing up in the logs
Changed log messages are not changed in the log files
Files that were once created and written to in code, but no longer touched by code, are still being created and written
I've tried everything I can think of to make this work. It was working at one point, but now it seems like it's no longer being updated. My process to integrate my changes into Mirth are:
Run an ant script to build the JAR file
Copy the JAR file to \lib\custom
Restart the Mirth service (via Mirth administrator)
I've tried restarting (Mirth service via Services, Java, computer) -- to no avail. I know my JAR file is correct, because I've decompiled it (to make sure it has the latest code) and hashed it (to compare to the hash of the ant-built JAR) -- it is correct and the code is there; it's just not being run.
I'm at wit's end; this occurs infrequently but completely blocks me from developing.
Edit: I also know that my code is correct, because when I run unit tests, it generates the right files and calls the right functions and logs the right information. Only Mirth seems to "not get it."
And my classes are very simple; simple one-argument constructors and a few public methods that return various data. Nothing complex, no nested classes/JARs/dependencies.
Edit: I even deleted my custom JAR file and restarted Mirth, and it's still running my code. Awesome :/ I've added a bounty for this question. I suspect the JAR is cached somewhere (even though they deny it on the Mirth forums) and that cache needs to be cleaned out somehow (although why restarting the Mirth service and my PC doesn't do it is beyond me).
I've also killed all instances of Java (and rebooted my computer), so that makes it highly unlikely that the JVM is caching the JAR somewhere.
I tried reinstalling Mirth. For some reason, it had my custom channel when I booted the administrator for the first time; and infuriatingly, it's still running the old JAR, even though I've updated it with the new one in lib\custom.
I ended up solving this with a combination of actions:
Uninstalling Mirth and Java, and then reinstalling.
I also removed all Java installations except one (one JDK and one JRE).
I stopped Mirth when you copying my JAR. Stop Mirth, copy, and restart; don't try to copy on a live installation. It may or may not pick up your updated JAR depending on if it's loaded into a JVM or not.
This combination of steps seemed to work. Prior to this, I had 3-4 JREs installed (and two JDKs) and I was copying (successfully, according to Windows 7) the JARs while Mirth was running. It's working now!
Mirth is a J2EE application running on a plain old JVM; you have options for debugging it.
You could follow the instructions here for running Mirth Connect via Eclipse. You could then see the JVM classpath, you could set breakpoints and use the debugger.
Mirth is based on the Mule ESB. Mule has its own way of class-loading. You could research it.
If Mirth is really using an old version of your JAR, maybe it's got a cached version around somewhere. Or maybe you made some configuration changes you've forgotten about - perhaps you added a new directory for jars. (Not sure how you do that.)
Mule pays attention to an environment variable named MULE_LIB; maybe that's relevant.
It looks like Mirth Connect 1.8 and Mirth Connect 2.0 have different places for jars (lib/custom and custom-lib, respectively). Which version are you using?

Untraceable exception in java applet

I'm having some problems tracing the reason that I can't load a java(fx) applet.
The java plugin console for the browser has always been my sole source of information for problem solving. The reason it isn't much help at the moment is that the applet starts to load, downloading the jar files and outputting a percentage to the console along with the occasional statement to say it's on the next jar file. At some point in time (different percentages each time) the console just closes unexpectedly and the applet stops loading. I know this isn't much to go on but I was wondering if there was any way that the output from the console could be stored to a file on the local machine. To debug this particular problem, changing security permissions temporarily would be acceptable.
The problem has occured on every pc i've tried, however if I keep refreshing after failure it seems to cache the jar files previously downloaded and thus get further through the loading process until it eventually works. My issue now is that on a particular customers network refreshing does not resolve the issue. I thought it may be a permissions issue writing to disk but I've tried an administrator account and still no luck. I've also tried a variety of browsers. It might also be worth noting that they go through a proxy server - when the applet tries to load it asks for the credentials for logging on to the proxy which seems to authorise fine.
If anyone has a suggestion on what I could try it would be gratefully received.
Thanks,
James
Two points:
You should be able to get a stack trace through the applet console viewer (which runs in the system tray on PC's) and if you open that up it will show you your stack trace for debugging.
Can you reproduce this problem using the Java Applet Viewer tool? This will allow you to write unit tests, and debug much more easily.
I forget where it is, but somewhere in the java control panel (one of the options under the advanced tab I believe) there's an option to turn on logging. This will log all output to the java console to a file as well. I've used this when trying to debug issues similar to this.
There's some info here on where the files will appear:
http://download.oracle.com/javase/1.5.0/docs/guide/deployment/deployment-guide/tracing_logging.html
The problem ended up being some JS code that was making calls to the applet before the applet had initialised.

Categories