Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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
"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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.