I have a curious situation. My code does not load the MANIFEST.MF
using getResourceAsStream()
on OpenJDK 1.6. On Oracle JDK 1.6+ it works well. I came across this when I was accidently running my code on OpenJDK.
main() method:
public static void main(String[] args) throws IOException {
InputStream is = Main.class.getClassLoader().getResourceAsStream("META-INF/MANIFEST.MF");
InputStreamReader isr = new InputStreamReader(is);
char[] c = new char[2048];
int read;
StringBuffer b = new StringBuffer();
while ((read = isr.read(c)) > 0) {
b.append(c, 0, read);
}
System.out.println(b.toString());
}
Maven JAR plugin definition:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>net.noorg.test.Main</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
Using OpenJDK 1.6:
$ java -version
java version "1.6.0_18"
OpenJDK Runtime Environment (IcedTea6 1.8.7) (6b18-1.8.7-2~squeeze1)
OpenJDK Client VM (build 14.0-b16, mixed mode, sharing)
$ java -jar target/test-load-resource-1.0-SNAPSHOT.jar
Manifest-Version: 1.0
Created-By: 1.6.0_18 (Sun Microsystems Inc.)
Using Sun JDK 1.6:
$ java -version
java version "1.6.0_29"
Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
Java HotSpot(TM) Client VM (build 20.4-b02, mixed mode, sharing)
$ java -jar target/test-load-resource-1.0-SNAPSHOT.jar
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: ABC
Build-Jdk: 1.7.0_07
Main-Class: net.noorg.test.Main
- Who's wrong - OpenJDK or I?
- Whats the reason for this?
- Is this only related to the Manifest or would this affect all resources?
Edit 1:
- Both execution use the same .jar
- Maven is running on Oracle JDK 1.7
- I'm running a system with two JDKs installed "defining" them trough
JAvA_HOME
andPATH
- I'm running the .jar on one machine using different
JAVA_HOME
's set andPATH
s set tojava
in two different consoles.
In addition to the above outputs
Open JDK (alternative JAVA_HOME/PATH not set):
$ echo "$JAVA_HOME" ; which java
/usr/bin/java
Sun JDK set:
$ echo "$JAVA_HOME" ; which java
/usr/local/jdk
/usr/local/jdk/bin/java
Edit 2:
If the JAVA_HOME
is properly defined for the OpenJDK (by default) it's the same.
$ echo "$JAVA_HOME" ; which java
/usr/java
/usr/bin/java
So it's not related to the empty JAVA_HOME
on my account.