Transmode / gradle-docker

A Gradle plugin to build Docker images from the build script.
Apache License 2.0
647 stars 142 forks source link

JVM parameters: Error: Could not find or load main class –Xms64m #114

Closed dcbasso closed 7 years ago

dcbasso commented 7 years ago

Hello,

I configure my docker-composer to use this: - JAVA_OPTS=–Xms64m -Xmx768m -XX:+UseG1GC -XX:+OptimizeStringConcat -Dcom.sun.management.jmxremote= -Dcom.sun.management.jmxremote.port=1100 -Dcom.sun.management.jmxremote.rmi.port=1100 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=192.168.99.100

But when my docker is starting I got this error: Error: Could not find or load main class –Xms64m

I change this line on "{project_name}/bin/gradle": exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" com.sollar.agricultural.Main "$@"

to: exec "$JAVACMD" –Xms64m -Xmx768m "${JVM_OPTS[@]}" -classpath "$CLASSPATH" com.sollar.agricultural.Main "$@"

And change the JAVA_OPTS to: - JAVA_OPTS=Dcom.sun.management.jmxremote= -Dcom.sun.management.jmxremote.port=1100 -Dcom.sun.management.jmxremote.rmi.port=1100 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=192.168.99.100

And everything appears to work just fine. But How can I pass some JVM parameters in docker without edit "{project_name}/bin/gradle"? What I can be doing wrong?

Thanks a lot!

dcbasso commented 7 years ago

I removed the arg " –Xms64m" and them the problem was solved.

jinshubao commented 6 years ago

我也遇到同样的问题

task buildDocker(type: Docker) {
    push = false
    exposePort(8080)
    setEnvironment("SERVER_PORT", "8080")
    setEnvironment('JAVA_OPTS', '-Xmx768m -Djava.security.egd=file:/dev/./urandom')
    addFile("${applicationName}-${version}.jar", "app.jar")
    volume("/tmp")
    entryPoint(["java", "\$JAVA_OPTS", "-jar", "app.jar"])
    doFirst {
        copy {
            from jar
            into stageDir
        }
    }
}

Dockerfile

FROM openjdk:8-jdk-alpine
MAINTAINER me me@test.com
EXPOSE 8080
ENV SERVER_PORT 8080
ENV JAVA_OPTS -Xmx768m -Djava.security.egd=file:/dev/./urandom
ADD test-app-1.0.jar app.jar
VOLUME ["/tmp"]
ENTRYPOINT ["java", "$JAVA_OPTS", "-jar", "app.jar"]

报错

Error: Could not find or load main class $JAVA_OPTS
jinshubao commented 6 years ago

添加插件

apply plugin: 'application'
apply plugin: 'docker'

增加配置

distDocker {
    push = false
    exposePort(8080)
    setEnvironment("SERVER_PORT", "8080")
    setEnvironment('JAVA_OPTS', '-Xms128m -Xmx768m -Djava.security.egd=file:/dev/./urandom')
    volume("/tmp")
}

执行命令

gradle clean distDocker

生成的Dockerfile如下

FROM openjdk:8-jdk-alpine
MAINTAINER test test@test.com
EXPOSE 8080
ENV SERVER_PORT 8080
ENV JAVA_OPTS -Xmx768m -Djava.security.egd=file:/dev/./urandom
VOLUME ["/tmp"]
ADD test-app-1.0.tar /
ENTRYPOINT ["/test-app-1.0/bin/test-app"]

运行正常,JAVA_OPTS 也生效