Can't find rt.jar when "jdk1.7.0_40" is specified in path

I just upgraded from Java 6 to Java 7 and now my gradle script can’t find rt.jar. Can anyone tell me why my gradle script complains that it can’t find rt.jar when referencing jdk1.7.0_40/jre/lib? But when I change it back to jdk1.6.0_37/jre/lib it finds it just fine? Or when I make a soft link to jdk1.7.0_40/jre/lib and reference the soft link it works too.

Here is where I am referencing it in my script when it doesn’t work:

subprojects {
    apply plugin: 'java'
    apply plugin: 'maven'
    repositories {
        flatDir { dirs "/opt/jdk1.7.0_40/jre/lib" }
        //mavenCentral()
        }
        sourceSets {
                main {
                        java {
                                srcDir 'src'
                        }
                        resources {
                                srcDir 'src'
                        }
                }
        }
}

Here is what it looks like when it does work, where the directory /lib is just a soft link to /opt/jdk1.7.0_40/jre/lib.

lrwxrwxrwx
1 root root
      33 Sep 30 15:04 lib -> /opt/jdk1.7.0_40/jre/lib/
subprojects {
    apply plugin: 'java'
    apply plugin: 'maven'
    repositories {
        flatDir { dirs "/opt/lib" }
        //mavenCentral()
        }
        sourceSets {
                main {
                        java {
                                srcDir 'src'
                        }
                        resources {
                                srcDir 'src'
                        }
                }
        }
}

It seems to me that that something is somehow excluding the rt.jar under /opt/jdk1.7.0_40/jre/lib when I have “jdk1.7.0_40” specified in the path. That really seems weird.

Any ideas? I would love to remove the bandaid of using a soft link.

Why do you specify ‘jre/lib’ as a flatDir repo? Can you show the corresponding dependency declarations?

Is this what you want to see?

subprojects {
    apply plugin: 'java'
    apply plugin: 'maven'
    repositories {
   flatDir { dirs "/th/software/jdk1.7.0_40/jre/lib" }
    flatDir { dirs "../lib" }
 //mavenCentral()
 }
 configurations {
                deployerJars
        }
        dependencies {
                deployerJars "org.apache.maven.wagon:wagon-http:2.2"
        }
 sourceSets {
  main {
   java {
    srcDir 'src'
   }
   resources {
    srcDir 'src'
   }
  }
 }
}
  project(':taxhawk2013') {
   dependencies {
  compile ':DynamicPDF'
  compile ':Serialio'
  compile ':USAePayAPI-jaxws-1.2'
  compile ':activation'
  compile ':anet-java-sdk-1.4.6'
  compile ':axiom-api-1.2.10'
  compile ':axiom-impl-1.2.10'
  compile ':bfopdf'
  compile ':cmu_time_awb'
  compile ':cmu_us_kal'
  compile ':cmudict04'
  compile ':cmulex'
  compile ':cmutimelex'
  compile 'com.yammer.metrics:metrics-core:2.1.2'
  compile 'com.yammer.metrics:metrics-graphite:2.1.2'
  compile ':commons-collections-3.2'
  compile ':commons-dbcp-1.4'
  compile ':commons-fileupload-1.2'
  compile ':commons-logging-1.1.1'
  compile ':cybsclients'
  compile ':cybssecurity'
  compile ':dBarcodePDF'
  compile ':en_us'
  compile ':freetts'
  compile ':gtftps'
  compile ':httpclient-4.0.1'
  compile ':httpcore-4.0.1'
  compile ':jakarta-regexp-1.4'
  compile ':javax.servlet'
  compile ':javax.servlet.jsp'
  compile ':javax.servlet.jsp.jstl'
  compile ':jcaptcha'
  compile ':jce-jdk13-115'
  compile ':jcert'
  compile ':jhlabs-image-filters'
  compile ':jsapi'
  compile ':jsf-api'
  compile ':jsf-impl'
  compile ':json_simple-1.1'
  compile ':jstl-impl'
  compile ':junit-4.8.2'
  //compile ':log4j-1.2.16'
  compile ':log4j-1.3'
  compile ':mail-1.4'
  compile ':mef_client_sdk_3.0'
  compile ':mindterm'
  compile ':mysql-connector-java-commercial-5.1.24-bin'
  compile ':ostermillerutils_1_06_01'
  compile ':rbarcode'
  compile ':rt'
  compile ':webservices-api'
  compile ':webservices-extra'
  compile ':webservices-extra-api'
  compile ':webservices-rt'
  compile ':xalan'
  compile ':xercesImpl'
  compile ':xml-apis'
  compile ':zmodem'
   }
 jar {
         manifest.attributes provider: 'gradle'
     }
}

or are you looking for the dependency in the code?

Here are the errors I get when specifying jdk1.7.0_40/jre/lib:

/var/lib/jenkins/jobs/someProject/src/captchas/JCaptchaImage.java:52: error: cannot find symbol
               JPEGImageEncoder jpegEncoder =
               ^
 symbol:
 class JPEGImageEncoder
 location: class JCaptchaImage
/var/lib/jenkins/jobs/someProject/src/captchas/JCaptchaImage.java:53: error: cannot find symbol
                       JPEGCodec.createJPEGEncoder(jpegOutputStream);
                       ^
 symbol:
 variable JPEGCodec
 location: class JCaptchaImage
  /var/lib/jenkins/jobs/someProject/src/captchas/JCaptchaImage.java:5: error: package com.sun.image.codec.jpeg does not exist
import com.sun.image.codec.jpeg.JPEGCodec;
                              ^
/var/lib/jenkins/jobs/someProject/src/captchas/JCaptchaImage.java:6: error: package com.sun.image.codec.jpeg does not exist
import com.sun.image.codec.jpeg.JPEGImageEncoder;

Here is what I get when I don’t include the jre/lib at all:

FAILURE: Build failed with an exception.
  * What went wrong:
Could not resolve all dependencies for configuration ':someProject:compile'.
> Could not find group:, module:rt, version:.

Why do you declare a compile dependency on ‘rt.jar’? You shouldn’t have to do this.

Because it can’t find the classes JPEGCodec and JPEGImageEncoder if I don’t.

/var/lib/jenkins/jobs/someProject/src/captchas/JCaptchaImage.java:52: error: cannot find symbol
               JPEGImageEncoder jpegEncoder =
               ^
 symbol:
 class JPEGImageEncoder
 location: class JCaptchaImage
/var/lib/jenkins/jobs/someProject/src/captchas/JCaptchaImage.java:53: error: cannot find symbol
                       JPEGCodec.createJPEGEncoder(jpegOutputStream);
                       ^
 symbol:
 variable JPEGCodec
 location: class JCaptchaImage
/var/lib/jenkins/jobs/someProject/src/captchas/JCaptchaImage.java:5: error: package com.sun.image.codec.jpeg does not exist
import com.sun.image.codec.jpeg.JPEGCodec;
                              ^
/var/lib/jenkins/jobs/someProject/src/captchas/JCaptchaImage.java:6: error: package com.sun.image.codec.jpeg does not exist
import com.sun.image.codec.jpeg.JPEGImageEncoder;

I just don’t get why if I reference jdk1.7.0_40/jre/lib it doesn’t work, but if I do jdk1.6.0_37/jre/lib it does.

I have no idea why this would happen. What happens if you add an explicit file dependency instead? E.g. ‘compile files("/opt/jdk1.7.0_40/jre/lib/rt.jar")’.

Where do I include that?

like this?

subprojects {
    apply plugin: 'java'
    apply plugin: 'maven'
    repositories {
         file("/opt/jdk1.7.0_40/jre/lib/rt.jar")
         flatDir { dirs "../lib" }
    //mavenCentral()
    }
    configurations {
                deployerJars
        }
        dependencies {
                deployerJars "org.apache.maven.wagon:wagon-http:2.2"
        }
    sourceSets {
        main {
            java {
                srcDir 'src'
            }
            resources {
                srcDir 'src'
            }
        }
    }
}
dependencies {
    compile files("/opt/jdk1.7.0_40/jre/lib/rt.jar")
}

Weird results again. It doesn’t work when it has jdk1.7.0_40 in there. But when I change it to use the soft link to the file it works.

dependencies {
    compile files("/opt/lib/rt.jar")
}d

My best (and wild) guess is that the Java compiler tries to prevent ‘rt.jar’ from being put on its compile class path. Ultimately, your question is about how to compile against an internal JDK API. Maybe this related Stack Overflow discussion will help you get further: http://stackoverflow.com/questions/19124873/sun-jpegimageencoder-compilation-in-gradle