0

I'm using sun.net.www.protocol.http.ntlm.NTLMAuthenticationCallback in a Java file.

The code builds and runs fine from Idea, but fails when using gradle compileJava.

I'm getting this error:

D:\source\msnavclient\MsNavClient.java:5: error: package sun.net.www.protocol.http.ntlm does not exist
import sun.net.www.protocol.http.ntlm.NTLMAuthenticationCallback;
                                     ^
D:\source\msnavclient\MsNavClient.java:20: error: cannot find symbol
        NTLMAuthenticationCallback.setNTLMAuthenticationCallback(new NTLMAuthenticationCallback()
                                                                     ^
  symbol:   class NTLMAuthenticationCallback
  location: class MsNavClient
D:\source\msnavclient\MsNavClient.java:20: error: cannot find symbol
        NTLMAuthenticationCallback.setNTLMAuthenticationCallback(new NTLMAuthenticationCallback()
        ^
  symbol:   variable NTLMAuthenticationCallback
  location: class MsNavClient
3 errors

I've found NTLMAuthenticationCallback class is in jre/lib/rt.jar, and tried adding the dependency directly in build.gradle file, but the problem persist.

This is the build.gradle file:

apply plugin: 'java'

repositories {
    mavenCentral()
}

dependencies {
    // compile files('C:\\Program Files\\Java\\jdk1.8.0_131\\jre\\lib\\rt.jar')

    testCompile group: 'junit', name: 'junit', version: '4.12'
}

Can anybody help please?

wOOdy...
  • 659
  • 13
  • 25

2 Answers2

0

I don't know if this is advisable, but try using the following (from here). Using it worked for me in a quick example of the issue:

compileJava {
    options.compilerArgs += ["-XDignore.symbol.file", "-Xdoclint:none", "-Xlint:none", "-nowarn"]
    options.fork = true
    options.forkOptions.executable = 'javac'
}
Michael Easter
  • 23,733
  • 7
  • 76
  • 107
0

Staring from @michael-easter answer, I found the compileJava task does not use the same procedure javac uses. And found this workarround to have rt.jar included in the classpath:

compileJava {
    options.bootClasspath = "${System.env.JAVA_HOME}/jre/lib/rt.jar"
}
wOOdy...
  • 659
  • 13
  • 25