Springboot app getting stuck at startup in Docker with Java 10 - java

Solution
Error existed between chair and keyboard
The problem was that the SPRING_PROFILES_ACTIVE environment variable was pointing to a profile that didn't exists. Changing it to the correct name fixed the issue. I would have expected Spring to output an error about that, but oh well.
Original question:
I have a "hello world" Java App build running with Spring boot in Java10. It runs fine directly on my machine, but when trying to start it up with docker it gets stuck with the following output:
(The Srping ascii art)
:: Spring Boot :: (v2.0.1.RELEASE)
WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (jar:file:/app.jar!/BOOT-INF/lib/groovy-2.4.15.jar!/) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
The process running:
java -Xmx800m -Djava.security.egd=file:/dev/./urandom -jar /app.jar
It runs fine directly on my laptop (Mac OS), and on my coworker's (Windows 7), but it fails in docker both locally and on Kubernetes (AWS)
I have tried configuring spring log level to DEBUG, but with no effect.
I also tried to edit $JAVA_HOME/conf/security/java.security to change directly the java securerandom.source property, which didn't work either.
Edit:
The dockerfile is a FROM using this:
FROM openjdk:10-jdk
RUN apt-get update && \
apt-get install -y openssl curl
ADD java.security /docker-java-home/conf/security/java.security
ONBUILD ARG BUILD_VERSION_NO="no-version"
ENV SPRING_PROFILES_ACTIVE=prod
#ENV JAVA_OPTS="-Xdebug -Xrunjdwp:server=y,transport=dt_socket,suspend=n"
ONBUILD COPY target/*.jar app.jar
ONBUILD RUN sh -c 'touch /app.jar'
ONBUILD RUN echo "$BUILD_VERSION_NO" > /version
EXPOSE 8080
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -jar /app.jar" ]
The java version in my laptop is
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
Packaging the app with the equivalent openjdk doesn't solve the problem
openjdk version "10.0.1" 2018-04-17
OpenJDK Runtime Environment (build 10.0.1+10)
OpenJDK 64-Bit Server VM (build 10.0.1+10, mixed mode)

Answering my own question in case someone else bumps into this:
The SPRING_PROFILES_ACTIVE environment variable contained "prod" whereas the spring profile in the application was "pro". Changing the value in the Dockerfile fixed the issue.

Related

Use different Java versions on single Ubuntu 18.04.4 LTS server

I have Jenkins server which works on Java 8 but, he should make mvn install before deployment. But compiled applications use Java 14.
After Java 14 was installed, Jenkins starting crash with
$ sudo service jenkins start Job for jenkins.service failed because the control process exited with error code. See "systemctl status jenkins.service" and "journalctl -xe" for details.
With Java 14
$ java -version
java version "14.0.1" 2020-04-14
Java(TM) SE Runtime Environment (build 14.0.1+7)
Java HotSpot(TM) 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)
Jenkins not work.
How I can be sure what Jenkins runs with the 8th version but my app compiling with the 14th version without Docker?
Perhaps I can use JRE from 8th and Compiler from 14th somehow? Or use 8th as active and 14th only for compile but how?
Java:
$ update-java-alternatives --list
java-1.8.0-openjdk-amd64 1081 /usr/lib/jvm/java-1.8.0-openjdk-amd64
java-14-oracle 1091 /usr/lib/jvm/java-14-oracle
Ubuntu: Ubuntu 18.04.4 LTS
I am not a Java/Jenkins developer.
Generally, in these cases where multiple program versions are involved, setting the application configuration to use a specific Java version works best, if the application supports that kind of configuration of course. You should check whether you can specify either of Jenkins or the compiler to use certain Java environment.
If that is not possible, then give it a try using environment variables. First, set Java 14 as the default so the compiler gets the latest version. Second, just before starting the Jenkins server, change Java environment temporarily, so that Jenkins sees Java 8 while running,
$ export JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-amd64" \
&& export PATH=$JAVA_HOME/bin:$PATH \
&& java -jar jenkins.war --httpPort=8080
On another note, using Docker in these scenarios is really a good idea. You should consider that.
I hope this helps.

"Error: Unable to access jarfile" if try'd to start from .sh script

I have the following problem: I would like to have a .sh file that starts a jar file so I have created one with nano and added the following:
java -jar myjarfile.jar
But Java gives me the following error "Error: Unable to access jarfile myjarfile.jar" so I tried to start it directly from the console with the same command. This works without problems so I checked the rights:
chmod 775 myjarfile.jar
chmod 775 start.sh
But I have exactly the same result. So I tried it with the root account but that did not help either. So slowly I'm a little bit desperate because I can not think of it anymore...
System information:
Linux version 4.9.0-8-amd64 (debian-kernel#lists.debian.org) (gcc version 6.3.0 20170516 (Debian 6.3.0-18+deb9u1) ) #1 SMP Debian 4.9.110-3+deb9u6 (2018-10-08)
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
Thanks for any answer :)

AWS Codedeploy fails with JAVA_HOME error

Have installed java 8 and
Java -version
yields
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
Having a AfterInstall script under hooks which simply has
cd $HOME/workspace
mvn clean install
AWS codedeploy is failing with following error
{\"message\":\"Script at specified location: scripts/start failed with exit code 1\",\"log\":\"LifecycleEvent - AfterInstall\\nScript - scripts/start\\n[stderr]Error: JAVA_HOME is not defined correctly.\\n[stderr] We cannot execute /usr/lib/jvm/jre/bin/java\\n\"}"}
echo $JAVA_HOME gives
/usr/java/jdk1.8.0_45/jre
Have also tried setting JAVA_HOME to
/usr/java/jdk1.8.0_45
When i try mvn clean install directly in the workspace it was able to pickup the Java correctly. Any idea what went wrong in code deploy?
hooks:
BeforeInstall:
- location: scripts/pre_processing
AfterInstall:
- location: scripts/start
Codedeploy seems works fine, it just run whatever script you gave.
This could be a problem of JAVA_HOME not accessible by current running user.
If you don't specify the runas parameter inside the appSpec, the scripts will run under root privilege by default(since the host agent starts with root privilege).
If this is the case, the possible workaround is either make JAVA_HOME accessible by root, or specify runas inside the appSpec for the AfterInstall script.

Rails 4: Solr throwing JavaMissing error, but Java is installed

I restarted my Rails 4 VPS and Solr was obviously also shutdown. I am now trying to startup Solr but when I run the following RAILS_ENV=production bundle exec rake sunspot:solr:start I get the following error message:
rake aborted!
Sunspot::Solr::Server::JavaMissing: You need a Java Runtime Environment to run the Solr server
/home/dani/.rvm/gems/ruby-2.1.2/gems/sunspot_solr-2.1.1/lib/sunspot/solr/server.rb:203:in `ensure_java_installed'
/home/dani/.rvm/gems/ruby-2.1.2/gems/sunspot_solr-2.1.1/lib/sunspot/solr/server.rb:27:in `initialize'
/home/dani/.rvm/gems/ruby-2.1.2/gems/sunspot_solr-2.1.1/lib/sunspot/solr/tasks.rb:37:in `new'
/home/dani/.rvm/gems/ruby-2.1.2/gems/sunspot_solr-2.1.1/lib/sunspot/solr/tasks.rb:37:in `server'
/home/dani/.rvm/gems/ruby-2.1.2/gems/sunspot_solr-2.1.1/lib/sunspot/solr/tasks.rb:5:in `block (3 levels) in <top (required)>'
/home/dani/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
/home/dani/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => sunspot:solr:start
(See full trace by running task with --trace)
The weird thing is that Java is installed:
$ echo $JAVA_HOME
/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java
$ java -version
java version "1.6.0_31"
OpenJDK Runtime Environment (IcedTea6 1.13.3) (6b31-1.13.3-1ubuntu1~0.12.04.2)
OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)
I'm not sure what might be causing this behavior. Any suggestions?
Try adding to PATH the folder where java is, like this:
export PATH=$PATH:/path/to/java/bin
so that java could be callable from everywhere without specifying the folder.
Launching this before calling rake solved the problem for me.

jmxtrans - Cannot execute

I am trying to get jmxtrans to work yet I get the below on ubuntu 12.04 and using openjdk 7.
/usr/share/jmxtrans# java -version
java version "1.7.0_25"
OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.12.04.2)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
/usr/share/jmxtrans# ./jmxtrans.sh start /var/lib/jmxtrans/kafka.json
Cannot execute /usr/lib/jvm/default-java/bin/jps -l!
What does the above mean?
It seems that the jps file can't be found in the /usr/lib/jvm/default-java/bin directory. It is available in the '-devel' packages if you want to install those (yum install java-1.7.0-openjdk-devel, apt-get install openjdk-7-jre-devel). It could also be that your JAVA_HOME is not pointing to the correct place if you have multiple java versions installed.
You should not need it however, regular ps works fine. You can add a variable to your configuration that says export USE_JPS=false. The configuration can be found in /etc/default/jmxtrans.
Check out these issues for more information:
https://github.com/jmxtrans/jmxtrans/issues/89
https://github.com/jmxtrans/jmxtrans/pull/109

Categories

Resources