I have used the Apache CLI library to create an executable jar file. I developed the program in eclipse and it runs just fine. However, i need to execute this on UNIX (solaris) environment and nothing seems to work. Here is the command i use
java -cp "$cPath" ./QueryHandler.jar "-i /home/xyzsd/java/QueryHandler/config/sybQuery.sql" "-U xxxxx" "-P xxxxxx,/" "-S Sybase" "-N xxxxxxx" "-s ##BusDate##=20150731" "-o /home/ertrgb/java/QueryHandler/config/output.xlsx"
$cPath has the path to all the jars i need.
export CLASSPATH=./:/usr/cvcv/fefef/wfvwerv/fefe/fwefwev/vswvrbvrb.jar:/usr
/cwvewv/dweqdecew/wevrrbrtb/wvvrtbtbb/cwweregrb.jar
cliPath=$invinvnrv/cli/1.3.1/*
jsonPath=$nrunvunrvunr/json/1.1.1/*
poiPath=$ivcnurnvrnvb/poi/3.10.1/*
cPath=$CLASSPATH:$cliPath:$jsonPath:$poiPath
When i try to execute this, i get an error saying that it could not find the JARs for Apache CLI. So, here are my questions
Do i have the correct syntax in trying to implement CLI in UNIX ?
Have i set up the paths to the needed JARs correctly ?
Please advise.
EDIT
ok so here is what i tried. i executed the main class for my jar as
java -cp $cPath MainHandler -i /home/xyzsd/java/QueryHandler/config/sybQuery.sql -U xxxxx -P xxxxxx,/ -S Sybase -N xxxxxxx -s '##BusDate##=20150731' -o /home/ertrgb/java/QueryHandler/config/output.xlsx
and this works ! however when i jar all of my files and try to execute
java -cp $cPath -jar QueryHandler.jar -i /home/xyzsd/java/QueryHandler/config/sybQuery.sql -U xxxxx -P xxxxxx,/ -S Sybase -N xxxxxxx -s '##BusDate##=20150731' -o /home/ertrgb/java/QueryHandler/config/output.xlsx
this throws the exception
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/cli/ParseException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2531)
at java.lang.Class.getMethod0(Class.java:2774)
at java.lang.Class.getMethod(Class.java:1663)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.cli.ParseException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 6 more
so basically, it cannot find the cli jar i guess. i also tried to include all the libraries i need in the jar file i create but i still get the same error.
Please advise.
EDIT 2
another update.
this works
java -cp $cPath:QueryHandler.jar MainHandler -i /home/xyzsd/java/QueryHandler/config/sybQuery.sql -U xxxxx -P xxxxxx,/ -S Sybase -N xxxxxxx -s '##BusDate##=20150731' -o /home/ertrgb/java/QueryHandler/config/output.xlsx
but i do not want to provide the name of the main class. i have already defined it in the manifest file.
Please advise.