473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problem with JAR

Hello everyone.
I have the following problem. I am sure that I am doing something very
silly, but I cannot figure out what it is.

I have the following structure for my Java application:

1) These are the directories I subdivided my code into:
../images
../sound
../libraries
../classes

and this is the main class

MAIN.class

'classes' contains the byte code of the program I wrote; 'libraries'
contains two .jar files that must be included in the classpath for my
application to run (actually to send e-mails). 'images' and 'sounds'
contain, respectively, images and sounds used in the application.

2) If I run the main class, the ./MAIN.class, from a normal shell everything
works fine (obviously setting the classpath).

3) If I package the classes in a .jar file, the application starts but:
- the two .jar files in libraries are not in the classpath causing the
application to receive an exception when trying to use classes in them;
- none of the files in the directories ./sound and ./images is
accessible. The relative path used in the various files in the 'classes'
directory, that is 'images/img1.jpg', works fine only if the class is not in
a .jar.

The .jar files has been created with the following command line:

jar cvfm mymanifest appl.jar MAIN.class classes libraries images sounds

where mymanifest is composed by the following lines:

Main-Class: MAIN
Class-Path: . libraries/mail.jar libraries/activation.jar

I do hope to find someone able and willing to help me.

Thank you in advance,
F.A. Cardillo
Jul 17 '05 #1
1 5345
Franco Alberto Cardillo wrote:
Hello everyone.

3) If I package the classes in a .jar file, the application starts but:
- the two .jar files in libraries are not in the classpath causing the
application to receive an exception when trying to use classes in them;
- none of the files in the directories ./sound and ./images is
accessible. The relative path used in the various files in the 'classes'
directory, that is 'images/img1.jpg', works fine only if the class is not in
a .jar.

The .jar files has been created with the following command line:

jar cvfm mymanifest appl.jar MAIN.class classes libraries images sounds

where mymanifest is composed by the following lines:

Main-Class: MAIN
Class-Path: . libraries/mail.jar libraries/activation.jar

I do hope to find someone able and willing to help me.


Franco,

Two points:

1) Please note that the Class-Path attribute of the manifest should
contain classpath entries expressed relative to the jar file itself, not
the contents of the jar file. That is, if the jar file is
/home/franco/appl/appl.jar, the effective classpath is:

/home/franco/appl/appl.jar:/home/franco/appl:/home/franco/appl/libraries/mail.jar:/home/franco/appl/libraries/activation.jar.

Note also that the executed jar is in the classpath as well.

2) I would consider it bad practice to access resources such as images
via a relative path depending on the current working directory. This is
the source of your other problem. The correct way (IMHO, of course) is
to use the Class.getResource(), Class.getResourceAsStream(),
ClassLoader.getResource() or ClassLoader.getResourceAsStream() methods
instead. When using these methods, you place the needed resources in
the classpath (in your case, in the appl.jar file) and access them
"relative" to the classpath. (There are some subtleties here with the
paths and exactly which method you use.) For example:

final ClassLoader loader = this.getClass().getClassLoader();
final URL go = loader.getResource("/images/go.gif");

HTH,
Ray
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
9
by: Sudesh Sawant | last post by:
Hello, We have an application which communicates using remoting. There is a server which is a Windows Service. The server exposes an object which is a singleton. The client is a Web Application...
117
by: Peter Olcott | last post by:
www.halting-problem.com
0
by: James Griffiths | last post by:
Here is a report I've written about a printing problem that is being experienced by a particular company for whom I had developed a A97 system. After upgrading to Win XP and AXP, some printing...
18
by: Ian Stanley | last post by:
Hi, Continuing my strcat segmentation fault posting- I have a problem which occurs when appending two sting literals using strcat. I have tried to fix it by writing my own function that does the...
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
9
by: AceKnocks | last post by:
I am working on a framework design problem in which I have to design a C++ based framework capable of solving three puzzles for now but actually it should work with a general puzzle of any kind and I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.