Reputation: 184
I'd like to know if I can develop my program with the current JRE 7u45 and later run it on an AS400 with IBM J9 VM build 2.4, JRE 1.6.0. Or will I have to use the 1.6.0 JRE to develop my program? As long as I don't use commands that were introduced later the program should work, shouldn't it?
Upvotes: 0
Views: 179
Reputation: 76918
There are two issues at play:
1) You can't use any new Java 7 features and attempt to generate 1.6 bytecode. Compiling with -source 1.6 -target 1.6
solves this problem. It will puke if you've done so (e.g. used the diamond operator; List<String> foo = new ArrayList<>()
)
2) You can't use new classes or new methods added to classes in 1.7. It will compile fine, then fail at runtime on the 1.6 JVM. This is a trickier problem. Using maven to build your project plus the animal-sniffer
plugin solves this issue:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Xlint:all</compilerArgument>
</configuration>
</plugin>
<plugin>
<!-- ensure that only methods available in java 1.6 can
be used even when compiling with java 1.7+ -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.9</version>
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java16</artifactId>
<version>1.1</version>
</signature>
</configuration>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
Upvotes: 1
Reputation: 75426
I do this daily.
The best way to be absolutely certain that the code will work as written without accidentally using features not present is to use java 6 for development. For eclipse that is installing a java 6 JDK and adding it to the Eclipse JRE preferences.
Note that the built in File support does not support CCSID's. Use IFSFile in jt400.jar instead.
Also, if you use JAVA or RUNJVA to invoke your program, you can use SystemDefaults.properties to provide system properties and JVM arguments. Check infocenter.
Upvotes: 1
Reputation: 200296
If you are careful enough with the APIs, you can make the Java 7 compiler produce Java 6-compliant bytecode, but it is not the default behavior.
I must add that this doesn't seem like a wise way to move; the APIs change in subtle as well as prominent ways and setting the "compliance level" parameters on the Java compiler will not prevent you from calling any methods which do not exist in JDK 6.
Upvotes: 3
Reputation: 1615
While you compile the program you need to use the "-target" flag and set it to 1.6
Upvotes: 0
Reputation: 4010
You should use JDK
instead of JRE
.
Also, use 1.6.0
instead of 1.7
because there are some features in version 1.7 that version 1.6 doesn't support.
Upvotes: 0