Running distribution inside docker container?

I built distribution and currently trying to run inside a Docker container but getting such error. Anyone knows what might be the problem?
glados-bot-container | Error: Could not find or load main class surik.simyan.glados.MainKt
glados-bot-container | Caused by: java.lang.ClassNotFoundException: surik.simyan.glados.MainKt
glados-bot-container | Error: Could not find or load main class surik.simyan.glados.MainKt
glados-bot-container | Caused by: java.lang.ClassNotFoundException: surik.simyan.glados.MainKt
FROM openjdk:22
RUN mkdir /app
COPY ./build/install/*-all.jar /app/glados.jar
RUN chmod +x /app/glados.sh
ENTRYPOINT ["/app/glados.jar/bin/glados.sh"]
FROM openjdk:22
RUN mkdir /app
COPY ./build/install/*-all.jar /app/glados.jar
RUN chmod +x /app/glados.sh
ENTRYPOINT ["/app/glados.jar/bin/glados.sh"]
plugins {
alias(libs.plugins.kotlinJvm)
application
}

group = "surik.simyan.glados"
version = "1.0.0"
application {
mainClass.set("surik.simyan.glados.MainKt")
distributions.forEach {
it.distributionBaseName.set("surik.simyan.glados-bot-$version-all.jar")
}
}
plugins {
alias(libs.plugins.kotlinJvm)
application
}

group = "surik.simyan.glados"
version = "1.0.0"
application {
mainClass.set("surik.simyan.glados.MainKt")
distributions.forEach {
it.distributionBaseName.set("surik.simyan.glados-bot-$version-all.jar")
}
}
35 Replies
$crooge MxDuck
$crooge MxDuckOP6mo ago
If I run disribution script, everything is working fine
gdude
gdude6mo ago
just sounds like your package or class name is incorrect you could open the JAR in an archive manager (or rename it to .zip) and check but I'm imagining it has something to do with your distributions.forEach which sets all distributions to the same JAR name I haven't actually seen that builder before, though, so just a hunch
$crooge MxDuck
$crooge MxDuckOP6mo ago
set -- \
-classpath "$CLASSPATH" \
surik.simyan.glados.MainKt \
"$@"
set -- \
-classpath "$CLASSPATH" \
surik.simyan.glados.MainKt \
"$@"
Isn't classpath ok?
gdude
gdude6mo ago
why are you setting that if you have a -all jar?
$crooge MxDuck
$crooge MxDuckOP6mo ago
Ah, copied it from jar task, seems like .jar in not needed here let me delete it Deleted
distributions.forEach {
it.distributionBaseName.set("surik.simyan.glados-bot-$version-all.jar")
}
distributions.forEach {
it.distributionBaseName.set("surik.simyan.glados-bot-$version-all.jar")
}
but the issue still remains
gdude
gdude6mo ago
did you check what was actually in the jar?
$crooge MxDuck
$crooge MxDuckOP6mo ago
there were two folders, bin and lib, I was running sh script inside bin folder
gdude
gdude6mo ago
What? That makes no sense How did those end up in your jar?
$crooge MxDuck
$crooge MxDuckOP6mo ago
It was not jar, I was not using fatJar, I ran ./gradlew installDist to create distributions Just I copy pasted the name from fatJar task, thats why it was named that way, my bad
gdude
gdude6mo ago
Isn't there another folder in build/install?
$crooge MxDuck
$crooge MxDuckOP6mo ago
no
gdude
gdude6mo ago
there should be at least according to the docs for the distribution plugin
You can run gradle installDist to assemble the uncompressed distribution into layout.buildDirectory.dir("install/${project.name}")
$crooge MxDuck
$crooge MxDuckOP6mo ago
Let me clean all and rerun it Here is the directory tree
└── glados
├── bin
│   ├── glados
│   └── glados.bat
└── lib
├── annotations-1.9.0-SNAPSHOT.jar
├── annotations-24.0.0.jar
├── api-jvm-0.5.4.jar
├── base64-2.3.9.jar
├── common-1.4.0.jar
├── commons-beanutils-1.9.4.jar
├── commons-codec-1.11.jar
├── commons-collections-3.2.2.jar
├── commons-digester-2.1.jar
├── commons-io-2.13.0.jar
├── commons-logging-1.3.2.jar
├── commons-validator-1.9.0.jar
├── glados-1.0.0.jar
├── httpclient-4.5.14.jar
├── httpcore-4.4.16.jar
├── icu4j-75.1.jar
├── jackson-annotations-2.17.1.jar
├── jackson-core-2.17.1.jar
├── jackson-databind-2.17.1.jar
├── java-semver-0.10.2.jar
├── jemoji-1.4.1.jar
├── json-20240303.jar
├── jsoup-1.16.1.jar
├── koin-core-jvm-3.5.6.jar
├── koin-logger-slf4j-3.5.6.jar
├── kord-common-jvm-0.15.0-SNAPSHOT.jar
├── kord-core-jvm-0.15.0-SNAPSHOT.jar
├── kord-core-voice-0.15.0-SNAPSHOT.jar
├── kord-extensions-1.9.0-SNAPSHOT.jar
├── kord-gateway-jvm-0.15.0-SNAPSHOT.jar
├── kord-rest-jvm-0.15.0-SNAPSHOT.jar
├── kord-voice-0.15.0-SNAPSHOT.jar
├── kotlin-logging-jvm-3.0.5.jar
├── kotlin-logging-jvm-7.0.0.jar
├── kotlin-stdlib-2.0.20-Beta1.jar
├── kotlin-stdlib-jdk7-2.0.20-Beta1.jar
├── kotlin-stdlib-jdk8-2.0.20-Beta1.jar
├── kotlinx-coroutines-core-jvm-1.8.1.jar
├── kotlinx-coroutines-jdk8-1.8.1.jar
├── kotlinx-coroutines-slf4j-1.8.1.jar
├── kotlinx-datetime-jvm-0.6.0.jar
├── kotlinx-serialization-core-jvm-1.7.1.jar
├── kotlinx-serialization-json-jvm-1.7.1.jar
└── glados
├── bin
│   ├── glados
│   └── glados.bat
└── lib
├── annotations-1.9.0-SNAPSHOT.jar
├── annotations-24.0.0.jar
├── api-jvm-0.5.4.jar
├── base64-2.3.9.jar
├── common-1.4.0.jar
├── commons-beanutils-1.9.4.jar
├── commons-codec-1.11.jar
├── commons-collections-3.2.2.jar
├── commons-digester-2.1.jar
├── commons-io-2.13.0.jar
├── commons-logging-1.3.2.jar
├── commons-validator-1.9.0.jar
├── glados-1.0.0.jar
├── httpclient-4.5.14.jar
├── httpcore-4.4.16.jar
├── icu4j-75.1.jar
├── jackson-annotations-2.17.1.jar
├── jackson-core-2.17.1.jar
├── jackson-databind-2.17.1.jar
├── java-semver-0.10.2.jar
├── jemoji-1.4.1.jar
├── json-20240303.jar
├── jsoup-1.16.1.jar
├── koin-core-jvm-3.5.6.jar
├── koin-logger-slf4j-3.5.6.jar
├── kord-common-jvm-0.15.0-SNAPSHOT.jar
├── kord-core-jvm-0.15.0-SNAPSHOT.jar
├── kord-core-voice-0.15.0-SNAPSHOT.jar
├── kord-extensions-1.9.0-SNAPSHOT.jar
├── kord-gateway-jvm-0.15.0-SNAPSHOT.jar
├── kord-rest-jvm-0.15.0-SNAPSHOT.jar
├── kord-voice-0.15.0-SNAPSHOT.jar
├── kotlin-logging-jvm-3.0.5.jar
├── kotlin-logging-jvm-7.0.0.jar
├── kotlin-stdlib-2.0.20-Beta1.jar
├── kotlin-stdlib-jdk7-2.0.20-Beta1.jar
├── kotlin-stdlib-jdk8-2.0.20-Beta1.jar
├── kotlinx-coroutines-core-jvm-1.8.1.jar
├── kotlinx-coroutines-jdk8-1.8.1.jar
├── kotlinx-coroutines-slf4j-1.8.1.jar
├── kotlinx-datetime-jvm-0.6.0.jar
├── kotlinx-serialization-core-jvm-1.7.1.jar
├── kotlinx-serialization-json-jvm-1.7.1.jar
├── ktor-client-content-negotiation-jvm-2.3.12.jar
├── ktor-client-core-jvm-2.3.12.jar
├── ktor-client-logging-jvm-2.3.12.jar
├── ktor-client-okhttp-jvm-2.3.12.jar
├── ktor-client-websockets-jvm-2.3.12.jar
├── ktor-events-jvm-2.3.12.jar
├── ktor-http-jvm-2.3.12.jar
├── ktor-io-jvm-2.3.12.jar
├── ktor-network-jvm-2.3.12.jar
├── ktor-serialization-jvm-2.3.12.jar
├── ktor-serialization-kotlinx-json-jvm-2.3.12.jar
├── ktor-serialization-kotlinx-jvm-2.3.12.jar
├── ktor-utils-jvm-2.3.12.jar
├── ktor-websocket-serialization-jvm-2.3.12.jar
├── ktor-websockets-jvm-2.3.12.jar
├── lava-common-2.2.1.jar
├── lavaplayer-2.2.1.jar
├── lavaplayer-natives-2.2.1.jar
├── map-jvm-0.5.4.jar
├── nanojson-1.7.jar
├── okhttp-4.12.0.jar
├── okio-jvm-3.7.0.jar
├── pf4j-3.12.0.jar
├── rhino-1.7.15.jar
├── rhino-engine-1.7.15.jar
├── sentry-7.11.0.jar
├── slf4j-api-2.0.13.jar
├── slf4j-simple-2.0.13.jar
├── stately-concurrency-jvm-2.0.6.jar
├── stately-concurrent-collections-jvm-2.0.6.jar
├── stately-strict-jvm-2.0.6.jar
├── token-parser-1.9.0-SNAPSHOT.jar
├── tomlkt-jvm-0.2.0.jar
└── v2-1.4.0.jar
├── ktor-client-content-negotiation-jvm-2.3.12.jar
├── ktor-client-core-jvm-2.3.12.jar
├── ktor-client-logging-jvm-2.3.12.jar
├── ktor-client-okhttp-jvm-2.3.12.jar
├── ktor-client-websockets-jvm-2.3.12.jar
├── ktor-events-jvm-2.3.12.jar
├── ktor-http-jvm-2.3.12.jar
├── ktor-io-jvm-2.3.12.jar
├── ktor-network-jvm-2.3.12.jar
├── ktor-serialization-jvm-2.3.12.jar
├── ktor-serialization-kotlinx-json-jvm-2.3.12.jar
├── ktor-serialization-kotlinx-jvm-2.3.12.jar
├── ktor-utils-jvm-2.3.12.jar
├── ktor-websocket-serialization-jvm-2.3.12.jar
├── ktor-websockets-jvm-2.3.12.jar
├── lava-common-2.2.1.jar
├── lavaplayer-2.2.1.jar
├── lavaplayer-natives-2.2.1.jar
├── map-jvm-0.5.4.jar
├── nanojson-1.7.jar
├── okhttp-4.12.0.jar
├── okio-jvm-3.7.0.jar
├── pf4j-3.12.0.jar
├── rhino-1.7.15.jar
├── rhino-engine-1.7.15.jar
├── sentry-7.11.0.jar
├── slf4j-api-2.0.13.jar
├── slf4j-simple-2.0.13.jar
├── stately-concurrency-jvm-2.0.6.jar
├── stately-concurrent-collections-jvm-2.0.6.jar
├── stately-strict-jvm-2.0.6.jar
├── token-parser-1.9.0-SNAPSHOT.jar
├── tomlkt-jvm-0.2.0.jar
└── v2-1.4.0.jar
gdude
gdude6mo ago
right
$crooge MxDuck
$crooge MxDuckOP6mo ago
plugins {
alias(libs.plugins.kotlinJvm)
application
}

group = "surik.simyan.glados"
version = "1.0.0"
application {
mainClass.set("surik.simyan.glados.MainKt")
}

repositories {
mavenCentral()
maven("https://jitpack.io")
maven("https://maven.lavalink.dev/releases")
maven {
name = "Sonatype Snapshots (Legacy)"
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
}

maven {
name = "Sonatype Snapshots"
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots")
}
}

dependencies {
implementation(libs.kord.core)
implementation(libs.kord.rest)
implementation(libs.kord.voice)
implementation(libs.kord.core.voice)
implementation(libs.kord.extensions)
implementation(libs.slf4j.simple)
implementation(libs.ktor.client.core)
implementation(libs.ktor.client.logging)
implementation(libs.lavaplayer)
implementation(libs.youtube)
testImplementation(kotlin("test"))
}

tasks.test {
useJUnitPlatform()
}


kotlin {
jvmToolchain(21)
}
plugins {
alias(libs.plugins.kotlinJvm)
application
}

group = "surik.simyan.glados"
version = "1.0.0"
application {
mainClass.set("surik.simyan.glados.MainKt")
}

repositories {
mavenCentral()
maven("https://jitpack.io")
maven("https://maven.lavalink.dev/releases")
maven {
name = "Sonatype Snapshots (Legacy)"
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
}

maven {
name = "Sonatype Snapshots"
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots")
}
}

dependencies {
implementation(libs.kord.core)
implementation(libs.kord.rest)
implementation(libs.kord.voice)
implementation(libs.kord.core.voice)
implementation(libs.kord.extensions)
implementation(libs.slf4j.simple)
implementation(libs.ktor.client.core)
implementation(libs.ktor.client.logging)
implementation(libs.lavaplayer)
implementation(libs.youtube)
testImplementation(kotlin("test"))
}

tasks.test {
useJUnitPlatform()
}


kotlin {
jvmToolchain(21)
}
And gradle build file
gdude
gdude6mo ago
and your dockerfile has COPY ./build/install/*-all.jar /app/glados.jar that's not going to copy everything
$crooge MxDuck
$crooge MxDuckOP6mo ago
I changed it to this
FROM openjdk:21
#COPY ./build/install/glados /app/glados
RUN chmod +x ./build/install/glados
ENTRYPOINT ["./build/install/glados/bin/glados.sh"]
FROM openjdk:21
#COPY ./build/install/glados /app/glados
RUN chmod +x ./build/install/glados
ENTRYPOINT ["./build/install/glados/bin/glados.sh"]
Tried even without copying
gdude
gdude6mo ago
..ok, well now you have nothing in the container the command you want is ADD ADD ./build/install/glados /app/glados then everything else has to happen from the context of /app/glados so probably WORKDIR /app/glados and work from there note that only the contents of build/install/glados will be added, there'll be no extra glados folder inside /app/glados
$crooge MxDuck
$crooge MxDuckOP6mo ago
So, we end up something like this?
FROM openjdk:21
ADD ./build/install/glados /app/glados
WORKDIR /app/glados
RUN chmod +x /bin/glados.sh
ENTRYPOINT ["/bin/glados.sh"]
FROM openjdk:21
ADD ./build/install/glados /app/glados
WORKDIR /app/glados
RUN chmod +x /bin/glados.sh
ENTRYPOINT ["/bin/glados.sh"]
gdude
gdude6mo ago
what do you mean by /bin/glados.sh you're not putting any files in /bin I'm getting the feeling that you don't know how unix filesystem paths work
$crooge MxDuck
$crooge MxDuckOP6mo ago
Wait, when we run ADD ./build/install/glados /app/glados don't we just add files from glados directory from install to /app/glados?
gdude
gdude6mo ago
yes, exactly not /bin
$crooge MxDuck
$crooge MxDuckOP6mo ago
Ok, and now my sh file is in /app/glados directly or what?
gdude
gdude6mo ago
according to your code block, it's in /app/glados/bin or ./bin since we set the workdir
$crooge MxDuck
$crooge MxDuckOP6mo ago
ok So is everthing right now?
FROM openjdk:21
ADD ./build/install/glados /app/glados
WORKDIR /app/glados
RUN chmod +x ./bin/glados.sh
ENTRYPOINT ["./bin/glados.sh"]
FROM openjdk:21
ADD ./build/install/glados /app/glados
WORKDIR /app/glados
RUN chmod +x ./bin/glados.sh
ENTRYPOINT ["./bin/glados.sh"]
gdude
gdude6mo ago
that looks correct
$crooge MxDuck
$crooge MxDuckOP6mo ago
cool, let me prune all and try to run it Nah, same error
glados-bot-container | Error: Could not find or load main class surik.simyan.glados.MainKt
glados-bot-container | Caused by: java.lang.ClassNotFoundException: surik.simyan.glados.MainKt
glados-bot-container | Error: Could not find or load main class surik.simyan.glados.MainKt
glados-bot-container | Caused by: java.lang.ClassNotFoundException: surik.simyan.glados.MainKt
Maybe something is wrong with compose file?
version: '3.9'

services:

kord:
build: .
image: ssimyan/glados:1.0.0
platform: linux/amd64
restart: always
container_name: "glados-bot-container"
version: '3.9'

services:

kord:
build: .
image: ssimyan/glados:1.0.0
platform: linux/amd64
restart: always
container_name: "glados-bot-container"
gdude
gdude6mo ago
you don't need the image property otherwise I don't think so technically you don't need platform either
$crooge MxDuck
$crooge MxDuckOP6mo ago
Well, I will later on publish it so I can pull it from my linux server to run it I'm currently on my local macOS machine
gdude
gdude6mo ago
oh, I didn't realise you could use compose for publishing anyway sounds like maybe you should try to inspect the image or contents of the container
$crooge MxDuck
$crooge MxDuckOP6mo ago
ok
gdude
gdude6mo ago
I haven't used gradle distributions so I'm not really sure
$crooge MxDuck
$crooge MxDuckOP6mo ago
Will try to found out, if nothing works, guess will need to try with fatJar, anyway, thanks
gdude
gdude6mo ago
might have something to do with the cwd on execution that's the only other hint I could think of I tested the distribution plugin locally and it worked, but I didn't put it into a container
$crooge MxDuck
$crooge MxDuckOP6mo ago
Yeah, similarly when I run it locally it works, but when try to run in container its failing
Want results from more Discord servers?
Add your server