1

I am trying to run a java project from the command line in linux, my project uses two external jar files. The command that i am givin is

java -classpath -jar bin:common-cli-1.2.jar:BuildFrameworkLibrary.jar com.kpit.goa.common.tools.kivibuild.KIVIBuild

where KIVIBuild is the class that contains the main function. But the error that am getting is:

baibhav@baibhav:~/git/KiviBuild/Infra/RepoManagement/BuildManagement/KIVIBuild$ java -classpath bin:common-cli-1.2.jar:BuildFrameworkLibrary.jar com.kpit.goa.common.tools.kivibuild.KIVIBuild

Gives

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/cli/ParseException
Caused by: java.lang.ClassNotFoundException: org.apache.commons.cli.ParseException
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    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)
Could not find the main class: com.kpit.goa.common.tools.kivibuild.KIVIBuild. Program will exit.
2
  • Is ParseException contained inside common-cli-1.2.jar? Commented Aug 19, 2013 at 14:37
  • java -classpath ".:bin/common-cli-1.2.jar:bin/BuildFrameworkLibrary.jar" com.kpit.goa.common.tools.kivibuild.KIVIBuild Commented Aug 19, 2013 at 15:12

2 Answers 2

3

You need a path separator e.g.

 bin/common-cli-1.2.jar:BuildFrameworkLibrary.jar 

The colon separates paths to individual jar files. e.g. in the above you're referencing the two files

bin/common-cli-1.2.jar
BuildFrameworkLibrary.jar

and also reference the directory containing your compiled classes e.g. if they're in (say) target/classes then use:

target/classes:bin/common-cli-1.2.jar:BuildFrameworkLibrary.jar

(relative to your current working directory)

Sign up to request clarification or add additional context in comments.

2 Comments

if i use path separator i.e java -classpath bin/common-cli-1.2.jar:BuildFrameworkLibrary.jar... or "." i.e java -classpath .:common-cli-1.2.jar:BuildFrameworkLibrary.jar.., then i get the error of : Exception in thread "main" java.lang.NoClassDefFoundError: com/kpit/goa/common/tools/kivibuild/KIVIBuild Caused by: java.lang.ClassNotFoundException: com.kpit.goa.common.tools.kivibuild.KIVIBuild. Program will exit. I used bin: as in linux classpath --help suggested this way to include the jar files. Jar files are present in the rootpath of the project.
Error is : Could not find the main class: com.kpit.goa.common.tools.kivibuild.KIVIBuild. Program will exit.
1

Use following command

javac -classpath bin/common-cli-1.2.jar:bin/BuildFrameworkLibrary.jar KIVIBuild.java -d .

Do not forget to add dot at the end of command

check is /com/kpit/goa/common/tools/kivibuild/KIVIBuild.class exist or not if yes run the following command

java -classpath bin/common-cli-1.2.jar:bin/BuildFrameworkLibrary.jar com/kpit/goa/common/tools/kivibuild/KIVIBuild

http://www.linuxheadquarters.com/howto/classpath.shtml

Rather than setting class path every time set it onces in existing classpath variable and just run the java command

1 Comment

I am still getting the error Could not find the main class: com/kpit/goa/common/tools/kivibuild/KIVIBuild. Program will exit. although KIVIBuild.class is present in the respective folder

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.