How date and time is handled inside WAR/ZIP? - java

The very same file inside the very same WAR file is displayed by jar tvf myfile.war as modified at different times at Linux ad Windows.
Linux:
ubuntu#alex2:~/trydeploy2$ jar tvf mywar.war | grep custom.css
23932 Thu Jan 05 02:03:04 UTC 2012 _diffs_classic/css/.sass-cache/custom.css
7580 Thu Jan 05 02:03:04 UTC 2012 _diffs_classic/css/custom.css
25817 Tue May 28 00:18:40 UTC 2013 css/.sass-cache/custom.css
7693 Tue May 28 00:18:40 UTC 2013 css/custom.css
Windows:
D:\>"C:\Program Files (x86)\Java\jdk1.6.0_25\bin\jar.exe" tvf mywar.war | grep custom.css
23932 Thu Jan 05 02:03:04 MSK 2012 _diffs_classic/css/.sass-cache/custom.css
7580 Thu Jan 05 02:03:04 MSK 2012 _diffs_classic/css/custom.css
25817 Tue May 28 00:18:40 MSD 2013 css/.sass-cache/custom.css
7693 Tue May 28 00:18:40 MSD 2013 css/custom.css
Last file is of interest.
As you see the time component values are coincide but timezones differ.
Machines are really at different timezones.
How to handle this situation? What information is stored inside ZIP and where a mistake can be? Finally I need Linux machine to know modification times correctly.

Related

Java, using class files from a .jar

so i am trying to use classes from a jar file i downloaded. The jar file is not in the same directory as the .java file that will use classes from the jar file.
I run
jar -tvf json-simple-1.1.1.jar
and I get
0 Sun Feb 19 14:30:56 CST 2012 org/
0 Sun Feb 19 14:30:56 CST 2012 org/json/
0 Sun Feb 19 14:30:56 CST 2012 org/json/simple/
3939 Sun Feb 19 14:30:54 CST 2012 org/json/simple/ItemList.class
2077 Sun Feb 19 14:30:54 CST 2012 org/json/simple/JSONArray.class
161 Sun Feb 19 14:30:54 CST 2012 org/json/simple/JSONAware.class
3076 Sun Feb 19 14:30:54 CST 2012org/json/simple/JSONObject.class
223 Sun Feb 19 14:30:54 CST 2012 org/json/simple/JSONStreamAware.class
3964 Sun Feb 19 14:30:54 CST 2012 org/json/simple/JSONValue.class
0 Sun Feb 19 14:30:56 CST 2012 org/json/simple/parser/
I want to implement ItemList.class, and I now know that it is in the package
org/json/simple/
so in my .java file I do
import org.json.simple.ItemList;
public class Foo(){
public static void main(String[]args){
ItemList i = new ItemList();
}
}
I now need to compile Foo() so I run
javac -cp '.;json-simple-1.1.1.jar' Foo.java
I get the error that the package org.json.simple does not exist but in github the class ItemList has package org.json.simple
Am I missing something? Thanks in advance
If the jar is not in the same directory you need to give the path to the jar directory when specifying the class path.

JFreeChart import error

Anyone can tell me where can I find the full version of JFreeChart? I downloaded the JCommon and JFreeChart as well (from the sourceforge page), but the JFreeChart contains only the jfreechart-demo.jar, so even if I correctly added the libraries in Eclipse, it doesn't work either...
Many Thanks!
When unpacked, the required JAR files are in the lib directory.
$ ls -ln lib
total 5800
-rw-r--r--# 1 501 20 45024 Jul 31 2014 hamcrest-core-1.3.jar
-rw-r--r--# 1 501 20 330246 Jul 31 2014 jcommon-1.0.23.jar
-rw-r--r--# 1 501 20 13796 Jul 31 2014 jfreechart-1.0.19-experimental.jar
-rw-r--r--# 1 501 20 79793 Jul 31 2014 jfreechart-1.0.19-swt.jar
-rw-r--r--# 1 501 20 1570157 Jul 31 2014 jfreechart-1.0.19.jar
-rw-r--r--# 1 501 20 50769 Jul 31 2014 jfreesvg-2.0.jar
-rw-r--r--# 1 501 20 245039 Jul 31 2014 junit-4.11.jar
-rw-r--r--# 1 501 20 445025 Jul 31 2014 orsoncharts-1.4-eval-nofx.jar
-rw-r--r--# 1 501 20 72444 Jul 31 2014 orsonpdf-1.6-eval.jar
-rw-r--r--# 1 501 20 80054 Jul 31 2014 servlet.jar
-rw-r--r--# 1 501 20 17492 Jul 31 2014 swtgraphics2d.jar
For example, the following command line runs TimeSeriesChartDemo1 on Unix; separate class path entries with a semicolon (;) on Windows.
$ java -cp .:lib/* org.jfree.chart.demo.TimeSeriesChartDemo1

Signing Jar files

I have purchased a code signing certificate for signing my jar files. After adding the whole chain of trust to the keystore, signing and validating the jar file I get this output:
sm 905 Tue Jul 22 15:48:42 CEST 2014 com/siemens/util/OSLogin$1.class
sm 881 Tue Jul 22 15:48:42 CEST 2014 com/siemens/util/OSLogin$2.class
sm 1802 Tue Jul 22 15:48:42 CEST 2014 com/siemens/util/OSLogin.class
s 434 Tue Jul 22 15:48:42 CEST 2014 META-INF/MANIFEST.MF
444 Tue Jul 22 15:48:42 CEST 2014 META-INF/_B8D178A3-25F1-4475-8D11-C37
A786279F4_.SF
6413 Tue Jul 22 15:48:42 CEST 2014 META-INF/_B8D178A3-25F1-4475-8D11-C37
A786279F4_.RSA
s = signature was verified
m = entry is listed in manifest
k = at least one certificate was found in keystore
i = at least one certificate was found in identity scope
jar verified.
Warning:
This jar contains signatures that does not include a timestamp. Without a timest
amp, users may not be able to validate this jar after the signer certificate's e
xpiration date (2017-07-21) or after any future revocation date.
But after copying the jar to the web server and opening the webpage on the same system I get "The certificate is not valid..."
Did I miss something? I'm new to code signing.
Regards
mannson

Avoid security alert "Do you want to run this application?" for a JWS app

We have a Java application that uses RxTx to update the firmware of our game console. To avoid security alerts when the users starts the Java application on our website through WebStart we have bought a trusted certificate and signed the application with that. All checks indicate that it is successfully signed and if I launch the application via Safari on my Mac(OS X 10.6.8) with Java 1.6.0_41 it starts without any complains.
But if I launch it using IE9 on a Windows 8 machine I get an alert saying "Do you want to run this application? This application will run with unrestricted access which may put your computer and personal information at risk. Run this application only if you trust the publisher. This application's digital signature has expired. More Information".
If I click the More Information I get "This application will run with unrestricted access to your personal files and other facilities(webcam, microphone) on your computer.
Although the application has a digital signature, the application's associated file(JNLP) does not have one. A digital signature ensures that a file is from the vendor and that it has not been altered.
The digital signature was generated with a trusted certificate."
I have tried to find a solution how to not get this message and think what I need to do is sign the JNLP file(i.e. copy it into the jar as pointed out here) but what I cannot find is how to get NetBeans to do that! I'm using NetBeans 6.9.1. Anyone know how to do this and if it is enough to sign the JNLP?
To verify that the file was correctly signed I did the following:
jarsigner -verify -certs -verbose OribooDesktopClient.jar
6396 Thu Feb 28 17:14:14 CET 2013 META-INF/MANIFEST.MF
6354 Thu Feb 28 17:14:14 CET 2013 META-INF/MOVINTOF.SF
1843 Thu Feb 28 17:14:14 CET 2013 META-INF/MOVINTOF.RSA
0 Thu Feb 28 17:07:28 CET 2013 META-INF/
0 Thu Feb 28 17:07:26 CET 2013 oribooDesktopClient/
0 Thu Feb 28 17:07:26 CET 2013 oribooDesktopClient/resources/
0 Thu Feb 28 17:07:26 CET 2013 oribooDesktopClient/resources/busyicons/
sm 3912 Thu Feb 28 17:07:26 CET 2013 oribooDesktopClient/BBDatabase.class
X.509, CN=Movinto fun AB, O=Movinto fun AB, STREET=?rev?gen 138, L=?re, ST=J?mtland, OID.2.5.4.17=83013, C=SE
[certificate is valid from 2/28/13 1:00 AM to 3/1/14 12:59 AM]
sm 2497 Thu Feb 28 17:07:26 CET 2013 oribooDesktopClient/Binary.class
X.509, CN=Movinto fun AB, O=Movinto fun AB, STREET=?rev?gen 138, L=?re, ST=J?mtland, OID.2.5.4.17=83013, C=SE
[certificate is valid from 2/28/13 1:00 AM to 3/1/14 12:59 AM]
....
The important part is:
This application's digital signature has expired.
See Appearance of Java Security dialog for details, but you should be expecting something like:
To remove the 'expired' message, the answer is to renew the certificate and sign the jars again. The dialog will still display words to the effect:
This application will run with unrestricted access which may put your computer
and personal information at risk. Run this application only if you trust the
publisher.
The differences will however be:
'Always trust' will default to true.
The yellow diamond with exclamation mark will be changed to something more friendly.
The 'digital signature has expired' message, along with the yellow shield image in the lower left, will be absent.

Error with image resources in jar file

I'm having a problem with running a jar file. If I compile the code in eclipse everything is ok, but when I export to jar and try to run the program it throws an error.
The error is:
Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at game.ChessSquare.<init>(ChessSquare.java:17)
at game.ChessFrame.DrawField(ChessFrame.java:131)
at game.ChessFrame.<init>(ChessFrame.java:38)
at game.Chess.main(Chess.java:7)
So the piece of code that throws this error is
//text is something like "pawn" or "king".The whole image is an icon on the button
img = new ImageIcon(getClass().getResource("white/"+text+".png"));
As I understand, it can't find the image so img variable is null. But I can't understand why then it does run in eclipse. Any help with this? Thanks
P.S #AndrewThompson
E:\Desktop>jar tvf chess.jar
49 Sat Feb 11 23:40:06 GMT 2012 META-INF/MANIFEST.MF
378 Sat Feb 11 22:51:04 GMT 2012 game/ChessFieldCoord.class
1932 Sat Feb 11 23:39:48 GMT 2012 game/ChessSquare.class
536 Sat Feb 11 22:51:04 GMT 2012 game/Chess.class
2122 Sat Feb 11 22:51:04 GMT 2012 game/Rook.class
2357 Sat Feb 11 22:51:04 GMT 2012 game/Bishop.class
1946 Sat Feb 11 22:51:04 GMT 2012 game/Queen.class
2127 Sat Feb 11 22:51:04 GMT 2012 game/Pawn.class
1630 Sat Feb 11 22:51:04 GMT 2012 game/Knight.class
878 Sat Feb 11 22:51:04 GMT 2012 game/Empty.class
1642 Sat Feb 11 22:51:04 GMT 2012 game/King.class
915 Sat Feb 11 22:52:32 GMT 2012 game/ChessFrame$1.class
841 Sat Feb 11 22:52:32 GMT 2012 game/ChessFrame$2.class
695 Sat Feb 11 22:52:32 GMT 2012 game/ChessFrame$3.class
3525 Sat Feb 11 22:52:32 GMT 2012 game/ChessFrame$Move.class
4675 Sat Feb 11 22:52:32 GMT 2012 game/ChessFrame.class
997 Sat Feb 11 22:51:04 GMT 2012 game/ChessFigure.class
928 Sat Feb 11 15:49:32 GMT 2012 game/black/bishop.png
1947 Sat Feb 11 15:49:10 GMT 2012 game/black/king.png
1247 Sat Feb 11 15:49:38 GMT 2012 game/black/knight.png
627 Sat Feb 11 15:49:44 GMT 2012 game/black/pawn.png
1668 Sat Feb 11 15:49:20 GMT 2012 game/black/queen.png
626 Sat Feb 11 15:49:26 GMT 2012 game/black/rook.png
1493 Sat Feb 11 15:48:30 GMT 2012 game/white/bishop.png
1889 Sat Feb 11 15:48:06 GMT 2012 game/white/king.png
1544 Sat Feb 11 15:48:40 GMT 2012 game/white/knight.png
1003 Sat Feb 11 15:48:48 GMT 2012 game/white/pawn.png
2440 Sat Feb 11 15:48:12 GMT 2012 game/white/queen.png
837 Sat Feb 11 15:48:20 GMT 2012 game/white/rook.png
The file where the error occurs is ChessSquare.class
img = new ImageIcon(getClass().getResource("/game/white/"+text+".png"));
Note the leading slash, as well as the game prefix.
As indicated in the comments, look in your jar (use winzip, 7zip, or something like that) to see where the resource is located. If it is not in a "white" directory then something is wrong with your jar build.
As to why it's running in Eclipse... that's likely because Eclipse is including the resource directory in the classpath when you run the program. This means that the getClass().getResource(...) call finds the png.
If you are keeping the file in a resources directory in Eclipse it also could be exporting the files into the META-INF directory in the jar, look in resources. If it is doing that then you may have setup the jar to be built for deployment into a web environment (see servlet 3.0 fragments).
One final note, be careful about using getClass().getResource(...) as it locks you down to only finding resources associated with the ClassLoader of the Class making that call (subject to how the ClassLoader hierarchy in question operates). You may want to provide extensions later where you can package other image sets in jars. In those cases you'll have to rely on slightly different mechanisms to get the images loaded (see ClassLoader.getResources as a starting point).
EDIT: This looks to be strictly an Eclipse problem. According to the way that the jar is structured the correct path is "game/white/king.png".
i'm an idiot, i finally figured out where the error was. As I wrote the output was "file:/E:/Desktop/Chess/bin/game/white/Pawn.png", notice the big P letter in Pawn.png. But the actual images' names started with small letters. That's why it didn't work. Still a mystery for me why then it worked in eclipse

Categories