Modified files not being sent during ANT build - java

We have been using Eclipse as our default IDE for some time and it has been a consistent source of headache, but moving away from it hasn't been an option because our build process is inexorably tied to it. I recently set us up to be able to build from VSCode. The problem is, that the build works for every computer except for mine and I can't for the life of me figure out why. When run from my computer, and only my computer, files that have been modified will fail to be detected during the build. What is even stranger is that, when Passive FTP is set to "yes", the files are simply ignored, as if they haven't been modified at all. When it is set to "no", however, I get this error:
SendPrivateMCS:
[ftp] sending files
[ftp] transferring C:\...\newtest.cfm
BUILD FAILED
C:\...\build.xml:1262: could not put file: 500 Illegal PORT command.
I get why I am getting this error. I am trying to send to a server configured for passive FTP. That's not a mystery. What is odd is that when active FTP is used, the test file that I modified is detected and an attempt is made to send it to the server, but when passive is used, it ignores it all together:
SendPrivateMCS:
[ftp] sending files
[ftp] 0 files sent
[ftp] sending files
[ftp] 0 files sent
[ftp] sending files
[ftp] 0 files sent
[ftp] sending files
[ftp] 0 files sent
Again, this only happens on my computer. The other devs are building just fine, in precisely the same way I am, and having no problems, which leads me to believe this is a problem with Java, Ant, or some sort of local FTP settings I'm not aware of but can't really figure out where to even begin looking. The build.xml file is the same one we have been using forever and hasn't been modified. I have tried reinstalling Java, reinstalling ANT, altering my environment variables, and looking for improperly uninstalled/deleted files and so far nothing has worked. I know all I have provided is some stack traces but there isn't really any code associated with this. I am just trying to run and ANT build from Powershell (ant Deploy -DDeployserver=foo) using a proven build.xml that has been in use here for at least half a decade. For some reason, it only sees my files when I use active FTP and can't seem to find any resources to help me figure out a possible cause. Any suggestions?

Ok, so I'm posting an answer to my own question because I finally came back to this project and we figured out the issue...sort of. Our server time is 6 hours ahead of my local time and the build file, for some reason, wasn't sure which time to use. I'm not sure why this happened, as it worked unmodified for everyone else and I verified that they were all seeing the same datetime entries I was, however, casting the server time zone explicitly for each ftp call did the trick for me and didn't break anything for them, so now we have a universal VSCode build that works for everybody. I'd still be interested if anyone has any information on why this worked at all. Since modifying the code wasn't necessary for anyone else to run this, I assumed that the problem must be with system settings, rather than the code, but the problem ended up being fixed by modifying the build.xml. The problem is fixed but I still have no idea why it didn't work in the first place or why the fix did work and would love it if anyone had clarification on that, but the issue is technically fixed and if anyone else has this problem, at least this is something you can try.

Related

Java JNLP download loop

We have a JNLP file that on some computers gets stuck in a download loop.
When the download it started the user is presented with an "Open" or "save" option and no matter which they choose it seems to start a new download and present them with the same 2 options.
It seems to only happen on Windows 10, though not always.
Java version is 8 update 161
The same thing appears to happen in Edge, Firefox, and Chrome.
Supposedly it was resolved one time by going into java configurations, and deleting temporary internet files, however I have not been able to replicate this issue.
Has anyone experienced this sort of thing? I tried searching around a bit online but nothing seems to match. This is the first time I've made an account to ask a question, please let me know if you think there is any other relevant data I should provide.
I figured this out. It seems users had associated the .jnlp file to "Open with" a browser, as a result any time they tried to open a .jnlp file they had downloaded the browser treated the file like a new download. We simply needed to re-associate the "open with" to point at the javaws.exe.
The piece that helped clarify this was realizing that the files were in the downloads folder, so they were downloading. They must have just chosen a poor association at some point.

Java's File.delete() sometimes leaves behind inaccessible files (Windows)

I am trying to programatically purge log files from a running(!) system consisting of several Java and non-Java servers. I used Java's File.delete() operation and it usually works fine. I am also perfectly fine with log files that are currently in use not being deleted, so I just log it as a warning whenever File.delete() returns false.
However, in log files which are currently still being written to by NON-Java applications (Postgres, Apache HTTPD etc., Java applications might also be affected, but I didn't notice yet, and all are using the same logging framework anyway, which seems to be OK) are not actually deleted (which is what I expected), however, File.delete() returns "true" for them.
But not only do these files still exist on the file system (Windows explorer and "dir" still show them), but afterwards they are inaccessible... when I try to open them with a text editor etc. I get "access denied" or similar error messages, when I try to copy them with explorer, it also claims that I do not have permissions, when I check its "properties" with explorer, it gives me "You do not have permission to view or edit this object's permissions".
Just to be clear: before I ran the File.delete() operation, I could access or delete these files without any problems, the delete operation "breaks" them. Once I stop the application, the file then disappears, and on restart, the application creates it from scratch and everything is back to normal.
The problem is that when NOT restarting the application after the log file purge operation, the application logs to nirvana.
This behavior reminds me a bit of the file deletion behavior of Linux: if you delete a file that is still held open by an application, it disappears from the file system, but the application - still holding a file handle - will happily continue writing to that file, but you will never be able to access it afterwards. The only difference being that here the files are still visible in the FS, but also not accessible otherwise.
I should mention that both my Java program and the applications themselves are running with "system" user.
I also tried Files.delete(), which allegedly throws an IOException indicating the error... but it seems there is no error.
What I tried to work around the problem is to check if the files are currently locked, using the method described here https://stackoverflow.com/a/1390669/5837050, but this only works for some of the files, not for all of them.
I basically need a reliable way (at least for Windows, if it worked also for Linux, that would be great) to determine if a file is still being used by some program, so I could just not delete it.
Any hints appreciated.
I haven't reproduced it but it seems like an OS expected behaviour, normally different applications run with different users which have ownership on this type of files but I understand that you want like a master purge Java which checks the log files not in use to delete them (running with enough grants of course).
So, considering that the OS behaviour is not going to change I would suggest to configure your logs with "roll file appender" policies and then check the files that match these policies.
Check the rollback policies for logback to make you an idea:
http://logback.qos.ch/manual/appenders.html#onRollingPolicies
For example, if your appender file policy is "more than one day or more than 1Gb" then just delete files which last edition date are older than one day or size are 1Gb. With this rule you will be sure to delete log files that are not in use.
Note that.. with a proper rolling policy maybe you even don't need your purge method, look at this configuration example:
<!-- keep 30 days' worth of history capped at 3GB total size -->
<maxHistory>30</maxHistory>
<totalSizeCap>3GB</totalSizeCap>
I hope this could help you a bit!!

Creating jar file directory across?

At first I have to say, that I've just started learning java a short while ago, so I'm not familiar with the language at all. Due to this, I try to get things done without using an IDE, so I can understand how things work. However, it's not the language that drives me crazy, but the process of making a .jar file.
I have the directories E:\Java\MyLib\mylib.java, E:\Java\Test\PartA\parta.java and E:\Java\Test\PartB\partb.java, which contains my main. mylib.java is a package that gets imported by parta.java, parta.java gets imported by partb.java.
I created a .bat file consulting several tutorials as much as the official specification from oracle about how to use the jar.exe, I've created a valid manifest.txt, I told the programm where it could find the partb.class containing my main, everything gets compiled to its own .class file just fine what tells me that my code is correct, but trying to merge all the files together into one .jar file took me hours without a working result.
According to any instructions I was able to find I'm doing everything right, I tried many different spellings and options, but at the end, either the compiler does not even find the files in the subfolders, or the files are in the .jar, but the javab.class is not able to find them during runtime.
It's sickening. I think I'm missing something, doing something absolutely wrong, but I can't figure out what it is. Any advice would be highly appreciated.
Use an IDE, it makes life so much easier. But, if you insist on doing things the old fashion way, try turning off your antivirus. If that doesn't work, check to make sure your environment variables are set correctly. If all else fails, try reinstalling your JDK.

Self updating game in java

I'm making a game, in Java, that has these following important features:
1) Connects to a remote Server (which i made), and will check for updates and install them if necessary
2) is NOT A SINGLE .JAR FILE (ie. has multiple .jar's and other things, such as .png, .wav, etc)
3) JAVA WEB START IS NOT AN OPTION, AS I WANT TO MAKE THIS ALL MYSELF
keeping the things above in mind, i have run into a problem. i have no clue how to implement a multiple "patch" update system. currently i have 1 .txt file, that the server reads from, and sends the files listed in the .txt to the client, which then moves them into place. The problem is, that is only useful for maybe 2 updates. I'm looking for a more useful, long term solution, and i need some help. here are some of the things i've thought of:
1) have a zip folder named after each version (problem: how would the client get ALL of the most updated files
2) have a .txt file INSIDE of each jar containing the version (problem: cant do that with png's or wav's, and i dont know how i would read the txt file to begin with)
i really need some help, i've tried googling it, i've thought about it for going on 3 weeks now, and cannot think of anything.
QUESTION: how would i make a game/program update with multiple patches?
Firstly, the best solution by a long, long way is to use Webstart / JNLP.
But if you insist on not using it (for whatever reason then) then it is technically possible. However:
It is messy and complicated.
It will either be very inefficient ('cos you have to load the entire program each time the user), or the user has to trust you enough to install your program with permissions that will allow it to install random stuff on his machine without notice.
The way to do it is to split the game into a launcher part and an application part. The launcher needs permissions to write and delete (non-temporary) files, and fetch stuff from the internet. It "calls home" to find out the latest version(s) of the application files, and then downloads and installs them. It has to cope with all sorts of error conditions, and it needs to make sure that nothing can trick it into installing bad stuff on the user's machine, etcetera, is someone spoofs your update service.
Of course, JNLP takes care of all of this, and lots more besides. People are going to be more willing to install the JNLP infrastructure that yours ... which might be insecure, or actively nasty (for all they know). (I for one wouldn't install a self updating application on my machine unless it was supplied by a company with impeccable credentials.)
I think you need here JNLP framework.
JNLP provides followed things:
allows to user to download jars from server
on launch verifies if application need to update
runs on local JVM
Actually, every java application you can convert to JNLP. Just to sign on all jars that your game contains, create executable jar from your game and create single Web page from where you can download your game

applet fails to load class from jar

Some users are complaining that the applet no longer works, When they view the java console they are greeted with a java.lang.noClassDefFoundError and checking my access log's I see they have downloaded the jar file that contains the class, and then issue a get request for the particular class.
Different users break on different classes.
Some users are fine.
Any ideas what could cause this/fix this.
I have checked to make sure the file is in their java cache, cleared the cache etc. nothing seems to fix them.
If they hit a qa site it breaks as well.
The jar is getting corrupted in transit, We are looking at getting patches from oracle/bea for the server.
It appears that if a connection is too slow (Modem speeds) that weblogic will signal the end of a transfer by sending a packet with len=0.
The network will signal java saying the download completed successfully and then java fails with a java.lang.noClassDefFoundError.
This can occur if the class itself can be loaded but some dependency of that class cannot be. Are there external JARs that are dependencies?
Are you sure the jar file contains all the necessary classes? Open it up in your favorite Zip application and double check. Maybe a recent build of that jar got messed up and doesn't have everything in it.
I'm assuming that you have made some updates by your wording. It is highly likely that some users have a previous Jar file cached.
When deploying a new applet version in a live configuration I perform the following:
Ensure the page holding the applet is not cached - use HTTP no-caching techniques. You may want to redeploy from a new page with these headers to ensure that it's not the case.
Deploy the jar file from a different URL for each update (I encode the version number in a directory, but you can equally rename the jar file).
If applet performs any client server interaction ensure that you check version numbers and report incorrect version to the user.
Even if you follow this the user may still have a problem, ask them to try these one at a time (listed in order they should try):
Press refresh on the browser window.
Restart all browser windows
Uninstall all Java VMs found on "Add/Remove programmes" and reinstall latest Java (yes, they must do this at their own risk!)

Categories

Resources