I've used this method before to load configfiles and jar files from an external directory with the main application packaged into a war, whilst it is messy, it does work.

From within a struts plugin...

ClassLoader loader = servlet.getClass().getClassLoader();
try {
URL configPathUrl = new URL( "file:" + basePath + File.separator + "config/" ); log.debug( "Adding Repository to search path '" + configPathUrl + "'" ); Method addRespositoryMethod = loader.getClass().getMethod( "addRepository" , new Class[]{ String.class } ); addRespositoryMethod.invoke( loader , new Object[] { configPathUrl.toString() } );

    // need to add each individual jar file to this search path
    File directory = new File( configPathUrl.getFile() );
    File[] jarFiles = directory.listFiles( new FileFilter() {
        public boolean accept( File input ) {
             return input.getName().endsWith( ".jar" );
        }
    });

    for ( int i=0; i< jarFiles.length; i++ ) {
log.debug( "Adding Repository to search path '" + jarFiles[i] + "'" ); Method addRespositoryMethodForJar = loader.getClass().getMethod( "addRepository" , new Class[]{ String.class } ); addRespositoryMethodForJar.invoke( loader , new Object[] { jarFiles[i].toURL().toString() } );
    }

    //log.debug( "Loader - " + loader );
}
catch ( Exception exp ) {
    log.error( "Unable to add repository path"  , exp );
}


The reason for invoking the methods via reflection is that I didn't want to make the tomcat libs a dependency for building the project.

Gareth

David Delbecq wrote:
It's rather not possible in general, The .war is supposed to be a 'complete' application, config included. If you load the ressources using the classloader, you can still use 'tricks' that depend on container specific behaviour, but that is not recommanded.

The best way if you want your user not to have to play thmeself with .war content is to provide a ant script that will take a config/ directory and inject it in the .war, so the user easily regenerate the war avec config change.


Pankaj Gupta wrote:
---------- Forwarded message ----------
From: Pankaj Gupta <[EMAIL PROTECTED]>
Date: Jun 28, 2006 11:03 AM
Subject: [OT] How to specify classpath for an application
To: user@struts.apache.org

Hi All,

I want to specify a config folder in my classpath which will not be part of
my war file. Can you please suggest how can I do that? I want to place my
config files outside the war file for anyone to modify it.

regards,
Pankaj



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



--
Gareth Evans

Software Developer

MSoft eSolutions Limited
Technology Centre
Inward Way
Rossmore Business Park
Ellesmere Port
Cheshire
CH65 3EN

--
Tel:    +44 (0)870 0100 704
Fax:    +44 (0)870 9010 705
E-Mail: [EMAIL PROTECTED]
Web:    www.msoft.co.uk

----------------------------------------------
Terms:
Please note that any prices quoted within this e-mail are subject to VAT.
All program details and code described in this e-mail are subject to
copyright © of MSoft eSolutions Limited and remain the intellectual
property of MSoft eSolutions Limited.
Any proposal or pricing information contained within this e-mail are
subject to MSoft eSolutions' Terms and Conditions
----------------------------------------------
Disclaimer:
This message is intended only for use of the addressee. If this message
was sent to you in error, please notify the sender and delete this
message. MSoft eSolutions Limited cannot accept responsibility for viruses,
so please scan attachments. Views expressed in this message do not
necessarily reflect those of MSoft eSolutions Limited who will not
necessarily be bound by its contents.



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to