I am using Drools Planner which ships with 21 Jar files in a directory binaries. For example the
drools-core-5.3.0.Final.jar would provide org.drools.someClasses.
The included examples run it in command line by running an all-inclusive command:
mainClasspath=
for i in binaries/*.jar; do mainClasspath=${mainClasspath}:$i; done
mainClass=org.drools.planner.examples.app.DroolsPlannerExamplesApp
$JAVA_HOME/bin/java -Xms256m -Xmx512m -server -cp ${mainClasspath} ${mainClass} $*
I am developing the program in commandline. But the final application (which just adds a HTTP interface) runs in a JSP container, not from a commandline. Hence I need to programmatically import the jar files into my project.
Question:How do I programatically import the the jar files?
Do I rather have to specify the binaries path in the environment variable?
Update
I did this to tell Java that globally, extra classes may be found in the same directory, meant by the . and /home/jesvin/dev/drools/binaries. Note that : is the separator in Linux.
declare -x CLASSPATH='.:/home/jesvin/dev/drools/binaries'
You can do it per execution instance as per Miserable Variable’s answer.
Finally, in a Tomcat deployment, I give it a HTTP interface, deploying it as per havexz’s answer.
If the jars need to be in global scope:
Well if you want these jars to be available to all apps on the server try putting them in
EDIT: @Geoffery comment: If you have access to
then you can added your own common jars dir like:
common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar,${catalina.base}/your_common_jar_folder/*.jar(See carefully at the end, I had added a new folder)
But either way, if the jars meant to be at global scope they should be in any of above folders. Else you have to put other common jars for logging and jdbc etc with every app.
If the jars need to be in app scope
And if you want these jars to be used only one specific app then put them in
Note: You can put the
<your_web_app>/WEB-INF/libof your development folder and if you are using the right tools then it will make these jars part of your.warfile.SIDE NOTE: Since you are running java program from command line too and having issues adding dependency jars. Sometime back I wrote a shell script for this purpose, hope this will help you too.
Small snippet of it: