slavig
slavig

Reputation: 339

Help to launch java app on linux

I have such bash script start.sh:

export JAVA_HOME=/home/qds/bin/jdk1.6.0_22
export QDS_HOME=/home/qds
$JAVA_HOME/bin/java -classpath $QDS_HOME/lib/*:$QDS_HOME/lib/commons/* com.qds.Main $@

In the directory /home/qds/lib I have necessary libraries and my jar file, wich contains:

com\qds\config
com\qds\entities
com\qds\hibernate
com\qds\protocols
com\qds\util
com\qds\Main.class

but when I run ./start.sh, I have:

./start.sh Exception in thread "main" java.lang.NoClassDefFoundError: com/qds/Main (wrong name: Main) at java.lang.ClassLoader.defineClass1(Native Method)

Upvotes: 0

Views: 562

Answers (2)

AlexR
AlexR

Reputation: 115328

Java does not support wildcards in option -classpath. Try to remove * from $QDS_HOME/lib/* and from $QDS_HOME/lib/commons/*

BTW this is relevant for windows too.

Classpath should contain 1. directories 2. explicitly written jar files.

If you have many jar files you can create script that composes the command line option. For example on linux

-classpath `ls -1|tr '\n' :`

composes classpath delimited with colon

Upvotes: 1

hhafez
hhafez

Reputation: 39750

You have to specify what your main class is going to be in one of several ways

  1. specify the main class name as an argument to the java command (just add the main class to the end of the your java command)
  2. Define it in your main jar's manifest

Upvotes: 1

Related Questions