0

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.

AbtPst
  • 7,778
  • 17
  • 91
  • 172
  • 1
    Try removing the '*' in the cliPath, jsonPath and poiPath. When the dirs have more than 1 file, it will be expanded to a set of files. Only the first file will be assigned to the righthand var, since you did not use quotes. Or use: `cliPath=$(echo "$invinvnrv/cli/1.3.1/*" | tr -c " " ":")` – Walter A Aug 10 '15 at 21:27
  • thanks Walter, but the * is not the issue. please see the edit – AbtPst Aug 11 '15 at 19:35
  • 1
    Try like [other question](http://stackoverflow.com/questions/5474666/how-to-run-a-class-from-jar-which-is-not-the-main-class-in-its-manifest-file) without the option `-jar`: add `MainHandler` in the cPath. – Walter A Aug 12 '15 at 20:11
  • thanks folks, but i guess the real problem is that i am trying to create a jar with all of my libraries packaged inside of it. apparently thats not possible using conventional methods. Any ideas on how to do this ? – AbtPst Aug 13 '15 at 13:20

0 Answers0