Wednesday 23 July 2014

Jetty 9.1 maven plugin error Unsupported major.minor version 51.0 when compiling for Java 6

Running a jetty server via the maven plugin gave me this error recently.

jetty run mojo Unsupported major.minor version 51.0

The stack trace looked like this:

Caused by: java.lang.UnsupportedClassVersionError: org/eclipse/jetty/maven/plugin/JettyRunMojo : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:386)
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)
    at org.sonatype.guice.bean.reflect.URLClassSpace.loadClass(URLClassSpace.java:101)
    ... 41 more


It turns out that if you are compiling for java 6 and you use jetty maven plugin v9.x you will get this unsupported version error. This is because the jetty maven plugin for v9.0 or higher requires java 7.

So change your jetty maven plugin in your pom to use Jetty version 8.1 if you need to target java 6.

Tuesday 22 July 2014

centOS 5 error Address family not supported by protocol when performing yum update

You're running 'yum update' on a centOS 5 box and get this error:

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=5&arch=x86_64&repo=os error was
[Errno 4] IOError: <urlopen error (97, 'Address family not supported by protocol')>
Error: Cannot find a valid baseurl for repo: base
The solution is that you need to setup your proxy, so open up a terminal and type as follows:

http_proxy="http://username:password@proxyurl:port/
export http_proxy
yum update
You should find that the yum command is executed without error:
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.joinweb.co.il
 * extras: centos.joinweb.co.il
 * updates: centos.joinweb.co.il
base                                                     | 1.1 kB     00:00
base/primary                                             | 1.3 MB     00:24
base                                                                  3662/3662

curl usage or how to post to a webservice from the commandline


curl is super for talking to http from the command line.

HTTP GET

In general, to use curl to do a GET request do as follows:

curl -v -H "header:value" http://host:port/webservice/uri

HTTP POST

To POST to a RESTful webservice, in this instance a JAX-RS Jersey REST service running on Jetty on an IBM AIX box:

  • Using curl 7.30.x from Windows
curl -H "header:value" -X POST -d "{json}" http://host:port/webservice/postResource
Note that you may have to escape the double quote in a json string, e.g. '{\"Key\":,\"Value\"}'  when posting the JSON data right on the command line.
  • Using curl 7.9.3 on the IBM AIX, the POST argument aint gonna fly:
curl -H "header:value" -X POST -d "{json}" http://host:port/webservice/postResource

Here's a tip - Passing the json on the command line is actually not great, its tough to read and tough to write out.

Rather create a file for the json packet and pass as an argument to curl like this:
curl -H "header:value" -X POST -d @myfilename.txt http://host:port/webservice/postResource

Wednesday 16 July 2014

Install curl on an IBM AIX

Get curl onto an IBM AIX. Here's how.

It is pretty simple - download curl from the IBM site
then run:
su -c rpm -Uvh curl-7.9.3-2.aix4.3.ppc.rpm
 done.