• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Linux classpath for jars

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've a library of jars from apache that I'm trying to set in a linux environment through a script. The code is



I run the script but I cannot compile the test.java file as the libraries don't seem to be recognized. The error is" package does not exist". It works fine in as a batch file but not in Linux. Am I doing something wrong?
 
Ranch Hand
Posts: 310
18
MS IE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are assigning only the first line to CLASSPATH. Every next line is interpreted as a separate line in your script (that has nothing to do with assignment to CLASSPATH).

If you put backslashes like this, all your paths will be interpreted as one single line, properly assigning your paths to CLASSPATH:
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I presume you use the script for a particular application? Don't you need to add :. to the end of the CLASSPATH?

Duplicating discussion in our Linux forum.
 
Krispin Kilmurray
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:I presume you use the script for a particular application? Don't you need to add :. to the end of the CLASSPATH?

Duplicating discussion in our Linux forum.


It is for a particular application. As for the :. I don't know. I have seen it in one or two examples but most were in the format I posted.
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might want to take a look at the catalina.sh file that comes in the bin directory of Apache Tomcat. It does that, something like this:


 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Krispin Kilmurray wrote:. . . As for the :. I don't know. . . .

What happens if you have any classes in whichever CLASSPATH begins in your current directory which need to be compiled as well? With an without the “:.”
 
Krispin Kilmurray
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Krispin Kilmurray wrote:. . . As for the :. I don't know. . . .

What happens if you have any classes in whichever CLASSPATH begins in your current directory which need to be compiled as well? With an without the “:.”


I get a no main in class error when running
 
Andrew Polansky
Ranch Hand
Posts: 310
18
MS IE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Include then . in your classpath:



Just be sure that you run the script from the directory where your java application is located.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alternatively you can give the absolute PATH to your Java folder as part of the CLSSPATH.
 
Krispin Kilmurray
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the replies folks but unfortunately it's still not working for me and I know it's something silly I'm doing wrong. This really has to be an easy solution. My home directory contents are as follows

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 the script (jar.sh) broken down for easy viewing



And this is the script (jar.sh) as it actually appears. It would be great if anyone could just point out what exactly is wrong.

#!/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:\.

 
Rancher
Posts: 4801
50
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you've got the whole classpath defined on one line then there is no need for the '\' characters.
 
Krispin Kilmurray
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the replies, I finally have it working.
 
Krispin Kilmurray
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, so it turns out I don't have it working. My script runs when it's this



but the libraries are not found. The code will execute until the POIFSFileSystem is called from the poi library then will crash. So I thought I'm not actually calling the classpath specified. However if I add in a -cp after java on the last line, I get an error could not load or find main class test2.jar. I think this is because I'm using the libraries specied in -cp which overides the jar call. At least thats what I got from the java documentation. This still does not allow me to solve my problem though.

Does anyone know how to fix this. Batch files are so easy compared to shell scripts. Googling isn't helping me on this one either. I need to run a jar file using a script that includes libraries located in other jar files.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you use the "java -jar thing.jar" command it ignores your classpath environment variable and expects to find a manifest entry in the executable jar specifying the classpath.
reply
    Bookmark Topic Watch Topic
  • New Topic