Ittikorn S. Ittikorn S. - 1 year ago 71
Linux Question

Linux command running JAVA with cronjob

I'm trying to setup a cronjob (cPanel) that execute a shell file which will run java application. However I can't get the class path to work.

JAVA folder application path


This command inside .sh file is working when running through terminal and inside the JAVA application folder

java -cp .:download.jar:log4j.jar:commons-httpclient.jar:commons-fileupload.jar:commons-logging.jar:commons-codec.jar:JAxe-1.0.jar portal.client.Main login

However when running outside the folder it doens't work and returns the following error

Error: Could not find or load main class portal.client.Main

so I try to specific class path

java -cp /home/user/public_html/version_1/data/downloader/* th.or.set.portal.client.Main login

It still showing error

log4j:ERROR Could not read configuration file []. (No such file or directory)
at Method)
at org.apache.log4j.PropertyConfigurator.doConfigure(
at org.apache.log4j.PropertyConfigurator.configure(
at portal.client.Main.main(
log4j:ERROR Ignoring configuration file [].
log4j:WARN No appenders could be found for logger (portal.controller.MainController).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.IllegalArgumentException: InputStream cannot be null
at javax.xml.parsers.DocumentBuilder.parse(
at portal.client.DownloadParameter.parseLoginParam(
at portal.controller.MainController.execute(
at portal.client.Main.main(

Answer Source

Well. You need to change workdir. You may do it simply by using cd

cd /home/user/public_html/version_1/data/downloader/
java -cp .:download.jar:log4j.jar:commons-httpclient.jar:commons-fileupload.jar:commons-logging.jar:commons-codec.jar:JAxe-1.0.jar portal.client.Main login
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download