LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-15-2016, 10:17 AM   #1
Kali84
LQ Newbie
 
Registered: Mar 2016
Posts: 5

Rep: Reputation: Disabled
Adding jars to classpath


Hi folks, I'm looking to use a script to add multiple jar libraries to CLASSPATH for a java project. Easy for me with a bat in Windows but I can't seem to get it to work on my amazon instance.

This is my home directory

ec2-user> test1.jar test2.jar poi-3.14 jar.sh

Test1.jar works fine and has no library calls from poi. Test2.jar gives a no main exception. poi-3.14 is the directory containing the poi jar files. jar.sh is my script as printed below. I've tried a few different things now such as changing the jar to tar in the file endings. Adding the . , adding the\ after the : and nothing seems to be working. I'm getting the same error each time.

This is my script

Code:
#!/bin/bash
export CLASSPATH=/home/ec2-user/poi-3.14/poi-3.14-20160307.jar:\
/home/ec2-user/poi-3.14/poi-scratchpad-3.14-20160307.jar:\
/home/ec2-user/poi-3.14/poi-ooxml-schemas-3.14-20160307.jar:\
/home/ec2-user/poi-3.14/poi-examples-3.14-20160307.jar:\
/home/ec2-user/poi-3.14/poi-excelant-3.14-20160307.jar:\
/home/ec2-user/poi-3.14/poi-ooxml-3.14-20160307.jar:\.
Am I doing something silly here?
 
Old 03-15-2016, 10:48 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,516

Rep: Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436
What is the error message you got?
Probably you need another construct, without \<newline>:
Code:
D=/home/ec2-user/poi-3.14
CLASSPATH=$D/poi-3.14-20160307.jar:$D/poi-scratchpad-3.14-20160307.jar:poi-ooxml-schemas-3.14-20160307.jar
CLASSPATH=$CLASSPATH:$D/poi-examples-3.14-20160307.jar:$D/poi-excelant-3.14-20160307.jar:poi-ooxml-3.14-20160307.jar
export CLASSPATH
 
1 members found this post helpful.
Old 03-15-2016, 11:23 AM   #3
Kali84
LQ Newbie
 
Registered: Mar 2016
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
What is the error message you got?
Probably you need another construct, without \<newline>:
Code:
D=/home/ec2-user/poi-3.14
CLASSPATH=$D/poi-3.14-20160307.jar:$D/poi-scratchpad-3.14-20160307.jar:poi-ooxml-schemas-3.14-20160307.jar
CLASSPATH=$CLASSPATH:$D/poi-examples-3.14-20160307.jar:$D/poi-excelant-3.14-20160307.jar:poi-ooxml-3.14-20160307.jar
export CLASSPATH
Thanks for the help pan64, I finally have it working. It took me way longer than it should have.
 
Old 03-15-2016, 11:45 AM   #4
Kali84
LQ Newbie
 
Registered: Mar 2016
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Kali84 View Post
Thanks for the help pan64, I finally have it working. It took me way longer than it should have.
Seems I spoke too soon. The programme is running now, which is more than before, but when the library call executes I'm getting a NoDefClassFoundError org/apache/poi/poifs/filesystem/POIFSFileSystem error.

Also, when I run 'echo $CLASSPATH' I get a blank return.

Last edited by Kali84; 03-15-2016 at 12:20 PM.
 
Old 03-15-2016, 12:50 PM   #5
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,516

Rep: Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436
so you did not set it properly. I do not know what did you do, so hard to give a hint...
 
Old 03-15-2016, 12:57 PM   #6
Kali84
LQ Newbie
 
Registered: Mar 2016
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
so you did not set it properly. I do not know what did you do, so hard to give a hint...
I uploaded the jar.sh file to my Linux server. Ran chmod +x jar.sh, then ./jar.sh. I then ran my test.jar (java -jar test.jar) which has the library calls but on executing the library call the error I mentioned occurred. Am I not running the script right. Should the classpath not print out when I echo $CLASSPATH?

Also I added in exec java -jar test2.jar. This starts my programme running. But when I have exec java -cp -jar test2.jar, I receive a could not loaf or find main class test2.jar error.

Last edited by Kali84; 03-15-2016 at 02:51 PM.
 
Old 03-16-2016, 03:39 AM   #7
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,516

Rep: Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436
was this CLASSPATH setting made in that jar.sh? ./jar.sh will start a new shell and CLASSPATH will be set inside that shell. The shell will be finished when the script completed and all the settings will be lost. The parent shell (your current one) will never know what's happened there.
If you want to set the current environment use:
source jar.sh
or
put java -cp -jar ... into that jar.sh
 
Old 03-16-2016, 08:51 AM   #8
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 7,506

Rep: Reputation: 2388Reputation: 2388Reputation: 2388Reputation: 2388Reputation: 2388Reputation: 2388Reputation: 2388Reputation: 2388Reputation: 2388Reputation: 2388Reputation: 2388
"Ninety-nine jars of code on the wall ... ninety-nine jars of code ..."

When building long and complicated path-strings, I use a series of export-commands, each of which adds one new file-name to the string, and each of which fits neatly on one (short ...) line in the file. The script is executed as part of the bash-profile. It can also be executed by the scripts which invoke the Java environment to do things.

From time to time I've also encountered scripts that read a list of library-names from a file and assemble these into an environment variable.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Where to find the JARs for javax.swing.* and java.awt.* jlinkels Programming 5 01-02-2009 08:46 PM
how to add external jars, Java program with Reference Libraries yuubouna Linux - Newbie 3 11-30-2008 10:19 PM
common jars for all JSP applications in tomcat in linux raghuveervellanki Linux - Newbie 1 10-17-2008 02:28 AM
How to work with jars and Ant ???????????????????? manolakis Programming 2 03-23-2007 05:54 AM
Java and Jars ? EAD Programming 6 12-31-2006 03:10 PM


All times are GMT -5. The time now is 01:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration