I am trying to build SSFnet simulator which is a network simulator developed in Java JDK 1.2.
After downloading it, I am trying to build it, but I got errors such as some unsafe functions has been used or some unsafe input has been used in your program etc. The problem is that I am using java 8 to run a program which has been developed with Java 1.2. Specifically, I get this error:
error: as of release 5, 'enum' is a keyword, and may not be used as an identifier
and
(use -source 1.4 or lower to use 'enum' as an identifier)
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
5 errors
Makefile:114: recipe for target 'SSF.OS' failed
make: *** [SSF.OS] Error 1
I tried to install java JDK 1.2 on my machine, but I get fragmentation fault kernel dumped error
I do not know if this is possible to run a program which has been developed with Java 1.2 with Java 8 or not and how can I handle this unsafe errors. I have no idea what should I do!
I haven't tried it, but javac -source 1.2 should do the trick.
According to the docs you should be able to use "source 1.2" in the javac 1.6 compiler.
https://docs.oracle.com/javase/6/docs/technotes/tools/windows/javac.html
Related
I understand the UnsupportedClassVersionError to be caused when I compile my java files in a newer version than the JVM the class file will be run on.
I'm working on a program that will run on an IBM i Series box, which is running Java 1.6. I've cross-compiled my files to use 1.5 for the source and target values. The actual command used is:
javac -source 1.5 -target 1.5 -bootclasspath C:/dev/languages/java/jdk1.5.0_22/jre/lib/rt.jar -extdirs "" -classpath "c:/dev/QIBM/ProdData/OS400/jt400/lib/*;/psmssys/java/src/com/gy/as400/common;." $(find ./com/gy/as400/bladder/install/* | grep .java)
Understand I am compiling the files on a Win 7 box running Java 1.8.0_131
Once the classes are compiled if I then run
javap -verbose
on any of the resulting classes, the Major Version shows 49which according to this wiki article should be compatible with JVM 1.5 and up.
I've tried to cross-compile to 1.4 but that would require me to rewite a significant portion of my code to not use FOR...EACH and generic lists.
What am I missing here.
Thank you #rdean400.
I got to thinking and went back through my transfer logs and found some errors had occurred moving the class from my dev box to the test box. I cleared out all the existing class files and transferred them again. This resolved the UnsupportedClassVersionError.
I am currently working on a class project with codename one and am running into issues with the built in InputStream and MediaManager classes. It keeps telling me that the feature I am attempting to use is from Java version 1.7.0_06 and to update when I am already using Java 1.8.
My error message is as follows:
java.io.IOException: This fetaure is supported from Java version
1.7.0_06, update your Java to enable this feature
My code is:
InputStream is = Display.getInstance().
getResourceAsStream(getClass(), "/"+fileName);
m = MediaManager.createMedia(is, "mp3",this);
I would post more of the error message/code but Stack overflows "indent" algorithm is messing up when I try to post the full code or error message.
The code you listed above should work for Java 5 and even before that so it's not the problem.
However you should run under Java 8 which is the minimum supported version for Codename One. Make sure your build.xml doesn't contain 1.5 references, if it does replace them all with 1.8. Also make sure the IDE's JVM is a Java 8 JVM and the language level is set to 8.
You might be using java 8 but your program is still executing on ols version. If you are using maven or ANT specify the version of java to 1.8 and if you are running through console, use below :-
http://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/javac.html
javac -source 1.8 -target 1.8 YourFile.java
I intend to write private-use command line tools in java for use both on my private system (jdk 7) and on my universities number-crunching servers (jre 1.4). An attempt at installing OpenJdk from sources failed, because it is missing several dependencies, that simply wouldn't make sense on a computation server -- e.g. CUPS. The work required for installing such dependencies and THEIR dependencies would probably defeat the whole point of automating tasks, i.e. making life easier.
Being used to the conveniences of generics, I don't want to write 1.4 SOURCE code though. I found that, when compiling from the command line, options like
javac -target 1.4 -bootclasspath jdk1.4.2/lib/classes.zip \
-extdirs "" OldCode.java
are available (see [1]), which should allow compiling jdk5 or even jdk7 specific syntax to jdk1.4 compatible bytecode, as long as I stay clear of newer library features (which -bootclasspath is for).
This brings up two problems:
While I can set the compliance level for each project to a given java version easily in Netbeans 7.3, it forces me to use 1.4 syntax as well (probably by adding -source 1.4 to the command above).
I couldn't find an old jdk (specifically classes.zip) anywhere except for oracle.com, where registration is required for downloading those with the registration mask alone making quite clear that those are not meant for private use.
All related answers I found so far give no hint how to do this kind of bytecode/source-separated cross-compilation in netbeans and none address the issue of finding old JDKs.
Eclipse is not really an option, as there I couldn't figure out how to get automatic generation of JARs like in netbeans.
Any ideas?
Platform details:
Local (from Netbeans "Help → About"):
Product Version: NetBeans IDE 7.3 (Build 201302132200)
Java: 1.7.0_11; Java HotSpot(TM) 64-Bit Server VM 23.6-b04
Runtime: Java(TM) SE Runtime Environment 1.7.0_11-b21
System: Windows 7 version 6.1 running on amd64; Cp1252; de_DE (nb)
Remote:
java version "1.4.2_11"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_11-b06)
Java HotSpot(TM) 64-Bit Server VM (build 1.4.2_11-b06, mixed mode)
Update: Just to be sure -- it IS possible to compile source with new syntax to Java 1.4. E.g. I wrote this file:
class Target<T>{
public T field;
public static void main(String[] args){
System.out.println("Hello World!");
Target<String> target = new Target<>();
target.field = "More Worlds.";
System.out.println(target.field);
}
}
Then I compiled it with JDK 7 doing
javac -target jsr14 Target.java
and uploaded it to the computation server, where only JRE 1.4 (and no JDK at all) is present. It gave the expected output
Hello World!
More Worlds.
Apparently the "jsr" targets are an undocumented feature though, see e.g. [2]. Also that link mentions, that it is a bit of a hack, as only for-each loops for the Collections library will be handled:
for-each loop: When iterating over an array, the compiler generates an induction variable and the standard array iteration idiom. When iterating over a Collection, the compiler generates the standard iterator-based idiom. When iterating over a non-Collection Iterable, the compiler produces an error.
I guess that means, that I will have no choice but to attempt getting a newer JRE onto the server, if I want to use any reasonably modern features...
[1] How do i compile a .java with support for older versions of java?
[2] http://twit88.com/blog/2008/08/26/java-understanding-jsr14/
JDKs aren't forward-compatible. That is, you cannot compile new features for old JDK versions. (or JRE for that matter).
Language constructs, such as generics, are if I'm not totally mistaken, part of the bytecode or interpreter in Java.
AFAIK you have only two options. 1) install new JDK or 2) write 1.4 source code.
Since the public Java 6 SE JRE is getting closer to it's EOL (Nov '12), I'm considering porting my projects from Java 6 to Java 7. This would'nt be a big deal, if Apple would provide a Java 7 JRE for Mac OS X. But since Apple isn't willing to do so, I still have to support users which only have a Java 6 JRE.
Is there a way to compile Java 6 compatible binaries (class files) with the Java 7 javac? Certainly I'm aware that I can't use the new Java 7 features when doing so.
Thanks in anticiption!
It depends. If your program doesn't use the new Java 7 language extensions, then you can run the Java compiler with the -source 1.6 and -target 1.6 options. But if you use Java 7 language extensions then -source 1.6 will result in compilation errors.
Certainly I'm aware that I can't use the new Java 7 features when doing so.
That includes Java 7 language features ... and dependencies on Java 7 changes to the standard class library APIs. Also be aware that there are small number of behavioural differences (aka API bug fixes) that may cause code to run differently on Java 6 and Java 7. They should be described in the Java 6 to Java 7 transition document.
UPDATE - This probably no longer an issue for you anyway, because Oracle have released Java 7 for Mac OSX.
i have jdk6 installed. if you check the man page of javac:
Cross-Compilation Options
By default, classes are compiled against the bootstrap and extension classes of the platform that javac shipped with. But javac also supports cross-compil‐
ing, where classes are compiled against a bootstrap and extension classes of a different Java platform implementation. It is important to use -bootclasspath
and -extdirs when cross-compiling; see Cross-Compilation Example below.
-target version
Generate class files that target a specified version of the VM. Class files will run on the specified target and on later versions, but not on earlier
versions of the VM. Valid targets are 1.1 1.2 1.3 1.4 1.5 (also 5) and 1.6 (also 6).
Yes, but in some cases no. In java 1.6 they didn't have the try with resources, switch with strings, or multi catch statements etc. So those parts of the program will not compile. But the idea of java is compile once, run everywhere; so code can work on old JVMs
Stephen C's answer is correct, but not complete. Your Java 7 programs won't compile in Java 6 if they use Java 7 language features, but be warned subtle other bugs can still occur with one developer coding in Java 6 and another compiling Java 7.
Take for example java.sql.Driver. In Java 7, the interface gained an additional method.
Java 7 Developer
This developer implements the Driver interface and uses the 'Override' annotation on the implemented additional Driver method. The program compiles fine as a Java 6 program because the class that the Java 6 compiler sees does have that method and the code gets checked in. Compiling the program as Java 6 does not mean that Java 6 compiler will automatically switch to use Java 6 source code!
Java 6 Developer
The Java 6 developer attempts to build the code the Java 7 developer committed and gets a compilation error even though the Java 7 developer was not implementing any Java 7 language constructs.
Consequently, even though you could compile it as Java 6, I would recommend not doing this.
I have two machines with difference JVM versions (1.6 and 1.5)
I have a JBOSS Server running on the one of JDK1.5. I've created a ejb jar file on the machine of JDK1.6.
When I get to deploy the EJB Jar into the JBOSS(4.3), I get the following error:
16:05:41,878 WARN [ServiceController] Problem creating service jboss.j2ee:service=EJB3,module=ejb1_test.jar
java.lang.ClassNotFoundException: Unexpected error during load of: org.daz.TimeServiceBean, msg=Bad version number in .class file
If you want to run in java 1.5 then you should compile in java 1.5 or lower.
Alternatively, if you simply must run JDK 6 then as #Paul Tomblin suggests you can use the -target javac option. One warning on this though, if you are using any of the new Java 1.6 API features javac 1.6 (e.g. setting File perms) javac will not complain but you will get errors when running this code in java 1.5.
javac has a -target option that allows you to compile to a 1.5 jvm with a 1.6 compiler. See javac -help for details.