0

Im building a java application that uses JDBC to connect to MySQL. I have an ant script that compiles my code and then packages it, along with log4j, junit, libshout-java and the mysql jdbc driver into one executable jar. This all works fine on ubuntu 9.10, and my code connects to mysql and away we go.

However my production env will be solaris (my dev box is ubuntu) and when I came to build and run this on there i had the following errors.

17 [main] DEBUG com.radiobusi.ShoutGen.ParseConfig  - [SQL, SELECT * FROM RadioBusi.RadioBusi_song JOIN RadioBusi.RadioBusi_playlist WHERE RadioBusi_playlist.Name = 'Placebo 2';]
18 [main] DEBUG com.radiobusi.ShoutGen.ParseConfig  - this is able to be broken up[SQL, SELECT * FROM RadioBusi.RadioBusi_song JOIN RadioBusi.RadioBusi_playlist WHERE RadioBusi_playlist.Name = 'Placebo 2';]
78 [main] ERROR com.radiobusi.ShoutGen  - An error occured instantiating the class ShoutGen
java.lang.ExceptionInInitializerError
        at com.mysql.jdbc.Util.stackTraceToString(Util.java:351)
        at com.mysql.jdbc.Util.<clinit>(Util.java:116)
        at com.mysql.jdbc.NonRegisteringDriver.parseURL(NonRegisteringDriver.java:672)
        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:277)
        at java.sql.DriverManager.getConnection(DriverManager.java:582)
        at java.sql.DriverManager.getConnection(DriverManager.java:185)
        at com.radiobusi.ShoutGen.PlayList.<init>(Unknown Source)
        at com.radiobusi.ShoutGen.ShoutGen.<init>(Unknown Source)
        at com.radiobusi.ShoutGen.ShoutGen.main(Unknown Source)
Caused by: java.lang.RuntimeException: Can't load resource bundle due to underlying exception java.util.MissingResourceException: Can't find bundle for base name com.mysql.jdbc.LocalizedErrorMessages, locale en_AU
        at com.mysql.jdbc.Messages.<clinit>(Messages.java:60)
        ... 9 more
Caused by: java.util.MissingResourceException: Can't find bundle for base name com.mysql.jdbc.LocalizedErrorMessages, locale en_AU
        at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1521)
        at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1260)
        at java.util.ResourceBundle.getBundle(ResourceBundle.java:715)
        at com.mysql.jdbc.Messages.<clinit>(Messages.java:58)
        ... 9 more
Exception in thread "main" java.lang.NullPointerException
        at com.radiobusi.ShoutGen.ShoutGen.main(Unknown Source)

My mysql database locale is en_US on solaris, but my ubuntu mysql database is the also en_US.

Anybody got any idea's?

Im not sure what other information is needed, so if you would like more information just let me know in the comments.

Jars that get packaged

junit-4.8.1.jar
libshout.jar
log4j-1.2.15.jar
mysql-5.1.6.jar

munderwo@opensolaris:~/ShoutGen-Java$ uname -a
SunOS opensolaris 5.11 snv_111b i86pc i386 i86pc Solaris

MySQL Version: MySQL 5.1.30

Cheers

Mark

PS this is a cross post from https://stackoverflow.com/questions/2036507/building-a-jar-with-mysql-jdbc-on-solaris as it kind of blurs the line between programming an sys-admin.

UPDATE 1:

the following ant target is how i packaged my jars. This means that the mysql jar is actually inside the jar and should be available to in automatically

<target name="jar">
        <!-- Capture the path as a delimited property using the refid attribute -->
        <property name="myclasspath" refid="classpath"/>
        <!-- Emit the property to the ant console -->
        <echo message="Classpath = ${myclasspath}"/>
        <mkdir dir="${jar.dir}"/>
        <jar destfile="${dest.file}" basedir="${classes.dir}">
            <manifest>
                <attribute name="Main-Class" value="com.radiobusi.ShoutGen.ShoutGen"/>
            </manifest>
            <zipfileset src="${lib.dir}/junit-4.8.1.jar" includes="**/*.class"/>
            <zipfileset src="${lib.dir}/libshout.jar" includes="**/*.class"/>
            <zipfileset src="${lib.dir}/log4j-1.2.15.jar" includes="**/*.class"/>
            <zipfileset src="${lib.dir}/mysql-5.1.6.jar" includes="**/*.class"/>
        </jar>
    </target>
Mark
  • 553
  • 6
  • 14

2 Answers2

0

make sure your jar is using the packed libs on your ubuntu box. Just move the libs in the filesystem temporarily to another location. When your jar runs, you can be sure the libs in the jar are used.

How did you reference the external libs from your jar? Did you add them to the Class-Path of your manifest file? When you did so, did you use relative or absolute paths?

Christian
  • 4,645
  • 2
  • 23
  • 27
  • Do you mean the shared libraries for mysql ie libmysqlclient etc? How do you add these to the jar Class-Path of the manifest file. – Mark Jan 12 '10 at 07:56
  • no, with libs i meen your additional jars for mysql, junit and log4j. – Christian Jan 12 '10 at 08:55
  • See Update 1 for my ant packaging. THanks again for your help! – Mark Jan 12 '10 at 11:22
  • take a look at this link http://onjava.com/pub/a/onjava/2003/12/17/ant_bestpractices.html. there is an example for a zipfileset. perhaps it helps. – Christian Jan 12 '10 at 12:09
0

I think the reason for this surprise, surprise, user error :)

I removed any mysql jdbc from my lib directory in my source code and then put the mysql jdbc connector that came with opensolaris (looks like it came from sun studio) in lib/ext of java. Once I did this it all seemed to work. On closer inspection I think I might have still had the ubuntu mysql JDBC driver in my class path and quite possibly before the cross-platform jar. So I suspect that this was the problem.

Thanks for all your help!

Mark.

Mark
  • 553
  • 6
  • 14