• Post Reply Bookmark Topic Watch Topic
  • New Topic

is there any shortcut to create classpath ?  RSS feed

 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there any shortcut to build a classpath?

when I run some application, it is required to add third-party jar file into classpath for javac, but I don't like to type so long file name. So I want to create a new folder under C:\, and hold all temp jar files inside the folder, and then I add this folder to system envoirment variable, ...

this is easiest for me. How to do this ?

Thanks
 
Marilyn de Queiroz
Sheriff
Posts: 9080
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which OS are you running on? There are different ways to set environment variables for different OSs.

Also, once you set your classpath inside a terminal window (using SET CLASSPATH), it stays set as long as that window stays open.
 
Anamika Agarwal
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is for windows operating system:
u should keep all the jar files in one folder as u probably are.Then edit your autoexec.bat file which recides in c:.Set the classpath variable as follows:
set classpath=%classpath%;c:\folderName\java40.jar;c:\folderName\jsdk.jar;c:\folderName\jweb.jar;c:\folderName\classes12.zip;
Here folderName refers to the name of folder in which u r keeping ur .jar files.
Then restart ur computer.
Hopefully this will help u.
 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, no, this is not what I want. It is me that mislead you guys.

It is not a classpath, similar to the class base directory, which hold all jar files. In the way above, I need type each jar file name into classpath, this way is time-wasted for me.

something like this,

set class-base-directory=c:\my-class-folder


Thanks
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edward, you could write a platform-specific script to add all JAR files in a specified directory to the CLASSPATH, or you could use a platform-independent scripting language such as Groovy to do the same. (At least I think you can do this with Groovy.)

Alternatively, I'd suggest taking a look at Ant, which has a feature to do what you're wanting to do that will work on any platform that Ant runs on. Plus, Ant does some other cool things.

For help getting started using Ant, take a look at Thomas Paul's article in the JavaRanch Journal, and mosey on over to the Ant, Maven and Other Build Tools forum.
[ September 08, 2004: Message edited by: Dirk Schreckmann ]
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hy Edward,

I have the feeling, that I'm the only one who understands .

You can add a folder to the classpath, which contains (a tree of ) class(es).
Or you add a jar to the classpath.

But you can not add a directory of jars to the classpath.

It's simply not possible.
Perhaps there is a reason for it - probably to avoid such situations as 'works for me - why not for you?' with unclear dependencies.
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Edward,

Just like what Stefan has said, it's not possible. This article by Sun confirms that.

Joyce
 
Holly Leery
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cant you just put a . in the classpath under environmental variables in the control panel?
 
Richard Bradford
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by countrygirl2149:
cant you just put a . in the classpath under environmental variables in the control panel?

I believe this would only add classes in the current directory to the classpath, not jar files.

As mentioned above, when using Ant, you can add multiple jar files to the class path using filesets.
[ September 09, 2004: Message edited by: Richard Bradford ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!