Compilation issues from the command line

I am trying to run everything from the linux command line to which I am relatively new too.

I am trying to compile a class which uses some external libraries and when i do javac classname.java i get warnings....

It is recommended that the compiler be upgraded.
warning: /opt/pi4j/lib/pi4j-core.jar(com/pi4j/io/gpio/GpioPinOutput.class): major version 51 is newer than 50, the highest major version supported by this compiler.

Even though it is just a warning - I have tried to then run java on the class file which results in

Exception in thread "main" java.lang.UnsupportedClassVersionError: com/pi4j/io/gpio/GpioFactory : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    at ControlGpioExample.main(ControlGpioExample.java:9)

I searched stackoverflow and found a post suggesting to use cross compilation - which I have tried via

javac -target 1.6 ControlGpioExample.java 

How do I know which target to use? Do i just keep going through them all until it works?!

Thanks

Jon Skeet
people
quotationmark

It's not the code you're compiling that's the problem - it's the code you're compiling against, in pi4j-core.jar, which appears to have been built with Java 7.

I strongly suggest you upgrade the JDK, basically. Either that, or:

  • Find a version of pi4j which was built with Java 6
  • Rebuild it yourself

people

See more on this question at Stackoverflow