how to load classpath entries for an SDK?

I created an SDK  type for IDEA. When a new SDK instance is created, my code adds Java jars and our own (Gosu) jars to the classpath (see the sample screenshot).
all the classpath entries are shown correctly when I close and reopen this dialog, but all *Gosu jars* are lost after I *restart* IDEA. I can only see the Java jars (see "gosu_sdk_after_restart.png").

I see "jdk.table.xml" file has all the requried information:

- <jdk version="2">
 <name value="Gosu SDK" />

 <type value="Gosu SDK" />

 <version value="java version "1.6.0_25"" />

 <homePath value="C:/gosu-0.9" />

- <roots>
- <annotationsPath>
 <root type="composite" />


- <classPath>
- <root type="composite">
 <root type="simple" url="jar://C:/Program  Files/Java/jdk1.6.0_25/jre/lib/alt-rt.jar!/" />

 <root type="simple" url="jar://C:/Program  Files/Java/jdk1.6.0_25/jre/lib/alt-string.jar!/" />

 <root type="simple" url="jar://C:/Program  Files/Java/jdk1.6.0_25/jre/lib/charsets.jar!/" />

 <root type="simple" url="jar://C:/Program  Files/Java/jdk1.6.0_25/jre/lib/deploy.jar!/" />

 <root type="simple" url="jar://C:/Program  Files/Java/jdk1.6.0_25/jre/lib/javaws.jar!/" />

 <root type="simple" url="jar://C:/Program  Files/Java/jdk1.6.0_25/jre/lib/jce.jar!/" />

 <root type="simple" url="jar://C:/Program  Files/Java/jdk1.6.0_25/jre/lib/jsse.jar!/" />

 <root type="simple" url="jar://C:/Program  Files/Java/jdk1.6.0_25/jre/lib/management-agent.jar!/" />

 <root type="simple" url="jar://C:/Program  Files/Java/jdk1.6.0_25/jre/lib/plugin.jar!/" />

 <root type="simple" url="jar://C:/Program  Files/Java/jdk1.6.0_25/jre/lib/resources.jar!/" />

 <root type="simple" url="jar://C:/Program  Files/Java/jdk1.6.0_25/jre/lib/rt.jar!/" />

 <root type="simple" url="jar://C:/Program  Files/Java/jdk1.6.0_25/jre/lib/ext/dnsns.jar!/" />

 <root type="simple" url="jar://C:/Program  Files/Java/jdk1.6.0_25/jre/lib/ext/localedata.jar!/" />

 <root type="simple" url="jar://C:/Program  Files/Java/jdk1.6.0_25/jre/lib/ext/sunjce_provider.jar!/" />

 <root type="simple" url="file://C:/gosu-0.9/jars/gw-asm-3.1.jar" />

 <root type="simple" url="file://C:/gosu-0.9/jars/gw-asm-analysis-3.1.jar" />

 <root type="simple" url="file://C:/gosu-0.9/jars/gw-asm-commons-3.1.jar" />

 <root type="simple" url="file://C:/gosu-0.9/jars/gw-asm-tree-3.1.jar" />

 <root type="simple" url="file://C:/gosu-0.9/jars/gw-asm-util-3.1.jar" />

 <root type="simple" url="file://C:/gosu-0.9/jars/gw-commons-cli-1.0.jar" />

 <root type="simple" url="file://C:/gosu-0.9/jars/gw-gosu-core-api.jar" />

 <root type="simple" url="file://C:/gosu-0.9/jars/gw-gosu-core.jar" />

 <root type="simple" url="file://C:/gosu-0.9/jars/gw-jline-0.9.94.jar" />

 <root type="simple" url="file://C:/gosu-0.9/jars/native-library-marker.jar" />



- <javadocPath>
 <root type="composite" />


+ <sourcePath>
 <root type="composite" />



 <additional jdk="1.6" />


now, the question is: HOW do I load all the Gosu jars from this file?

Comment actions Permalink

I can see in the Expression Evaluator window that the Gosu JAR entries are loaded (see screenshot "idea_expression_evaluator.png").
how can I access them? and/or why aren't they shown on the SDK's "classpath" tab?

UPDATE: one thing I noticed is that Gosu Jars URLs start with "file://", while Java ones start  with "file://" - that might be the reason...

Comment actions Permalink

btw, this is the code I'm using to set up the SDK:

  public static void setUpSdk(Sdk gosuSdk, @Nullable Sdk javaSdk, Sdk[] allSdks) {
    GosuSdkAdditionalData data = new GosuSdkAdditionalData(gosuSdk, javaSdk);

    String sdkName = GosuSdkType.SDK_NAME;
    sdkName = SdkConfigurationUtil.createUniqueSdkName(sdkName, Arrays.asList(allSdks));

    final SdkModificator sdkModificator = gosuSdk.getSdkModificator();


    if (javaSdk != null) {

    addJavaJarsToOurClasspath(javaSdk, sdkModificator);
    addOurJarsToClasspath(sdkModificator, gosuSdk);

  private static void addOurJarsToClasspath(SdkModificator sdkModificator, Sdk gosuSdk) {
    File gosuRootDir = new File(gosuSdk.getHomePath());
    File gosuJarsDir = new File(gosuRootDir, GOSU_SDK_JARS_FOLDER_NAME);
    File[] jars = getFilesInDirectory(gosuJarsDir, FILE_EXTENSION_TO_ADD_TO_GOSU_SDK_CLASSPATH, false);
    for (File file : jars) {
      String urlString = VfsUtil.pathToUrl(file.getAbsolutePath());
      VirtualFile virtualFile = VirtualFileManager.getInstance().findFileByUrl(urlString);
      sdkModificator.addRoot(virtualFile, OrderRootType.CLASSES);

  private static void addJavaJarsToOurClasspath(Sdk javaSdk, SdkModificator sdkModificator) {
    for (VirtualFile file : javaSdk.getRootProvider().getFiles(OrderRootType.CLASSES)) {
      sdkModificator.addRoot(file, OrderRootType.CLASSES);

  public static File[] getFilesInDirectory(File dir, String suffix, boolean recursive) {
    String[] dirContents = dir.list();
    List result = new ArrayList();
    for (int i = 0; dirContents != null && i < dirContents.length; i++) {
      String dirContent = dirContents[i];
      if (dirContent.endsWith(suffix)) {
        File file = new File(dir, dirContent);
        if (file.isDirectory() && recursive) {
          result.addAll(Arrays.asList(getFilesInDirectory(file, suffix, recursive)));
    return (File[]) result.toArray(new File[result.size()]);

Comment actions Permalink

ok, I figured it out.

I should have added JAR entries instead of regular files:

      VirtualFile virtualFile = VirtualFileManager.getInstance().findFileByUrl(urlString);
--> NEW -->        VirtualFile jarFile = JarFileSystemImpl.getInstance().getJarRootForLocalFile(virtualFile);
        sdkModificator.addRoot(jarFile, OrderRootType.CLASSES);


Please sign in to leave a comment.