简体   繁体   中英

How to get the classpath of a Java application running on webstart?

My Java application, deployed via webstart, invokes a helper application. I want to start the helper application in a separate JVM with the the same classpath as the main application.

Without webstart, the system ClassLoader provides an answer. With webstart, the system ClassLoader provides the path to deploy.jar only.

I found this , but it seems to be out of date. It refers to at least one method on internal API com.sun.deploy.cache.Cache that has since vanished from Java 8u60. Perhaps there is another way.

Sorry to say, but searching the cache will only work for as long as a new update of the jws application is not downloaded. The classpath will contain references to all directories with old and new versions.

I use a C++-dll for this purpose called from the jws application

HMODULE thisDll = GetModuleHandle(TEXT("MyDll.dll"));
    ::GetModuleFileName(thisDll, currentDir, sizeof(currentDir));
_splitpath(currentDir, Ldrive, Ldirpath, Lfname, Lext);
sprintf(currentDir,"%s%s",Ldrive,Ldirpath);

After that I parse currentDir to find all jar files.

Here is something that works (in Jython) with Java 8u66. Obviously, I would prefer a solution that does not depend upon internal APIs. But, perhaps that is not available.

import com.sun.deploy.cache.Cache as Cache
import traceback
classPath = []
for indexFile in Cache.getCacheEntries(False):
    try:
        cacheEntry = Cache.getCacheEntryFromFile(indexFile)
        jarFile = cacheEntry.getJarFile()
        if jarFile is not None:
            classPath.append(jarFile.getName())
    except:
        traceback.print_exc()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM