```File file = new File( getClass().getClassLoade...
# announcements
g
Copy code
File file = new File(
	getClass().getClassLoader().getResource("database.properties").getFile()
);
Is this really the best way to access files in the resources folder?
n
Beware: there’s no guarantee that there is a resources folder. That depends on the implementation of the classloader. The getFile method may return an empty string if the resource URL isn’t hierarchical, and will include the query parameters of the URL if there are any.
t
The recommended way is to use
getResourceAsStream
(if memory serves)
g
Failed day... thought I got it working but I cant seem to build a docker image from the path
t
Are you passing that off to the spotify docker client by any chance?
g
I don't think I tried that one, was working with docker-java/dockerjava but not docker-java-api, lol. 1 hour working with the CLI I'm able to run docker commands, I don't think I need this package, general CLI commands (I think) are going to work out better for me... open to alternatives, but after 48 hours I think it might be best.
Yeah, think I'm building my own at the CLI... open to being talked out of it... but after 1 hour I'm hoping along nicely. Just the basics obviously.
Copy code
fun String.runCommand(workingDir: File): String? {
    try {
        val parts = this.split("\\s".toRegex())
        val proc = ProcessBuilder(*parts.toTypedArray())
            .directory(workingDir)
            .redirectOutput(ProcessBuilder.Redirect.PIPE)
            .redirectError(ProcessBuilder.Redirect.PIPE)
            .start()

        proc.waitFor(60, TimeUnit.MINUTES)
        return proc.inputStream.bufferedReader().readText()
    } catch(e: IOException) {
        e.printStackTrace()
        return null
    }
}

class DockerImageApi(val workingDir: File) {
    fun build(tagName: String, fileName: String): String? {
        return "docker image build -t $tagName -f $fileName .".runCommand(workingDir)
    }
}

class DockerApi(val workingDir: File) {
    val image = DockerImageApi(workingDir)

    val images = fun (): String?{
        return "docker images".runCommand(workingDir)
    }
}

fun main(){
    val dockerFile = File(DockerApi::class.java.classLoader.getResource("dockerfiles")!!.file)
    val docker = DockerApi(dockerFile)

    println(docker.images())
    println(docker.image.build("test2", "svrDB"))
    println(docker.images())
}
t
Yeah… I’d just use the Spotify docker client, it does all the heavy lifting for you and will pick the right transport mechanism
119 Views