Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Classpath limitation in Linux

Tags:

java

linux

We are executing standalone java program from shell script, having a comman script to mention classpath, path, etc..In this common script, we have added several classpaths now and number of character is more than 9000. It is working fine in the test env. Will it cause any issue in Production? Any limitation is there in linux to set classpath? What is the max char for command line inputs...

like image 240
Ganesan MP Avatar asked Oct 08 '22 09:10

Ganesan MP


1 Answers

No, there is no limitation. In Windows there is (8191 characters), but not under Linux. We work with the concept of classpath-files. These file lists all the dependencies for the application, eg:

...
libs/org/easymock/easymock/2.2/easymock-2.2.jar
libs/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1.jar
libs/org/hibernate/hibernate-envers/4.1.0.Final/hibernate-envers-4.1.0.Final.jar
libs/com/google/inject/guice/3.0/guice-3.0.jar
...

and then we convert this into usable classpath and run the application as follows:

#!/bin/bash

CLASSPATH_FILE=`ls -r1 ${APP-HOME}/classpaths/myapp*.classpath | head -n1`
CLASSPATH=$(cat $CLASSPATH_FILE | sed 's_^libs_ ${APP-HOME}/libs_' | tr -d '\n' | tr -d '\r' | sed 's_.jar/libs/_.jar:/libs/_g' | sed 's_.pom/libs/_.pom:/libs/_g')

java -d64 -cp $CLASSPATH com.blah.main.Main $@

We have never run into problems and these classpath entries gets pretty huge.

EDIT: As a side note, you can use the maven dependency plugin to generate a list of dependencies.

like image 130
Jaco Van Niekerk Avatar answered Oct 12 '22 20:10

Jaco Van Niekerk