classpath question

I have a bunch of libraries in Jar format located in .\lib.

When I am trying to launch the program.

I cannot have

java myprogram -cp ./lib

instead I have to type every single files

java myprogram -cp ./lib/a.jar;./lib/b.jar...

Besides typing manually, are there productivity tips to construct very long classpath?

[356 byte] By [ssiua] at [2007-11-26 15:31:10]
# 1
batch file/shell script/mac equivalent ?If your libraries are legitimate extensions, you could put them in/ext
es5f2000a at 2007-7-8 21:48:00 > top of Java-index,Java Essentials,Java Programming...
# 2

You sould create a shell or batch script that takes a list of directories as input, finds all the jar files in those directories, and concats them together into a classpath.

Or you could pass the directories to your Java progam at startup, and then in your program use a java.io.File to scan the directories for jar files and add those jar files to a [url http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLClassLoader.html]URLCassLoader[/url].

jverda at 2007-7-8 21:48:00 > top of Java-index,Java Essentials,Java Programming...
# 3
Windows DOS batch script would be nice. Appreciate if I can follow an sample template. (which concatenates filenames recursively)I wish the java launcher just accept the path or have a seperate property file that specify all jar files, to reduce the verboseness.
ssiua at 2007-7-8 21:48:01 > top of Java-index,Java Essentials,Java Programming...
# 4
Or, you could do some work yourself and search for it.
es5f2000a at 2007-7-8 21:48:01 > top of Java-index,Java Essentials,Java Programming...
# 5
If you're running JDK 6, you can do this: java -cp lib/* YourClass Otherwise, you could take a look at the batch files/shell scripts that come with [url= http://ant.apache.org/]Ant[/url] for an example of building a "dynamic" classpath.
uncle_alicea at 2007-7-8 21:48:01 > top of Java-index,Java Essentials,Java Programming...
# 6
Or, you could do some work yourself and search for it.Don't be a yutz.Message was edited by: hohonuuli
hohonuulia at 2007-7-8 21:48:01 > top of Java-index,Java Essentials,Java Programming...
# 7

All of the examples I've found don't deal with paths with space very well. Here's an example to solve the problem:

Create a batch file to launch your java app or setup your environment. It's contents will look something like:

@echo off

REM $Id: $

REM Setup the APP environment

REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

REM APP_HOME assumes that your batch file is in APP_HOME\bin.

REM If your batch file is in APP_HOME change the next line to 'SET APP_HOME=%~dp0'

SET APP_HOME=%~dp0..

SET APP_LIB=%APP_HOME%\lib

SET APP_CLASSPATH=

FOR %%i IN ("%APP_LIB%\*.jar") DO CALL cpappend.bat %%i

Create a second batch file name cpappend.bat. It's contents will be:

rem

rem Append to APP_CLASSPATH

rem

rem $Id: $

rem

SET _TEMP=

REM Process the first argument

IF ""%1"" == """" GOTO end

SET _TEMP=%1

SHIFT

REM Process the remaining arguments. Paths with spaces are handled here

:setArgs

IF ""%1"" == """" GOTO doneSetArgs

SET _TEMP=%_TEMP% %1

SHIFT

GOTO setArgs

REM Build the classpath

:doneSetArgs

SET APP_CLASSPATH=%APP_CLASSPATH%;"%_TEMP%"

GOTO end

:end

Message was edited by:

hohonuuli

Message was edited by:

hohonuuli

hohonuulia at 2007-7-8 21:48:01 > top of Java-index,Java Essentials,Java Programming...