Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes Unable to access classes in a jar file Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Unable to access classes in a jar file" Watch "Unable to access classes in a jar file" New topic
Author

Unable to access classes in a jar file

sylvia greene
Ranch Hand

Joined: Jun 23, 2004
Posts: 40
I have a folder called src. In this folder i have a jar file log4j-1.2.7 which contains packages. In the same folder src i have another package com.abc which has a file App.java
When i compile this class it cannot access classes within the jar file.

structure is something like this

src\log4j-1.2.7.jar

and

src\classes\com\abc\App.java

I am writing
D:\>src\classes>javac com\abc\App.java

It's unable to find the classes in jar file
Shashank Agarwal
Ranch Hand

Joined: May 20, 2004
Posts: 105
Could you please write the error message that you are recieving.
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Hi Sylvia,

I think your problem may be twofold. Firstly the directory structure of your application; secondly your classpath.

Set up your application directory structure something like the following:

This is the conventional way of setting up a Java app.

Ensure the following directories are on your classpath:

If you're using an IDE then set the classpath in your IDE configuration.
On the command line, you can specify the classpath as follows (ignoring the classes directory):

Or set the environment variable 'classpath' as follows:

Note that setting the classpath environment variable in a command window is only persistent as long as the command window is open (i.e. it doesn't change your system settings)

From the src directory, you should then be able to execute:

If successful the class file will appear in the same directory as App.java.
To create the classes in your myapp\classes directory add "-d D:\java\myapp\classes" to the command line.

Just a note about Log4J: Log4J is a very well designed and easy to use logging API, but are you aware that Java 1.4 has its own logging API, very similar to Log4J, in the java.logging package?

Alternatively, if you don't want to mess around with fancy hierarchical directory structures just stick everything under the D:\src directory and make sure it's on the classpath.

Hope you find this useful.

Jules
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Shashank,

Welcome to JavaRanch!

We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.

Thanks Pardner! Hope to see you 'round the Ranch!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Unable to access classes in a jar file
 
Similar Threads
Websphere 3.5, Log4j 1.2.7
The abstract path of IO
Help! Wsdl2Java Can't parse a Coldfusion WSDL?
package com.example.model ERROR
Ant task for renaming folder?