How to fix several (permission related) exceptions with Lift and Jetty? - java

I'm trying to deploy a small Lift webapp to a Jetty container but I get several exceptions. I pasted a small excerpt of the stack trace below. I can provide the full stack trace if needed. I goggled all three problems but I couldn't find anything useful to solve it.
I created my app.war file in sbt with the package command and just dropped the web archive inside Jetty webapps folder.
~$ whereis jetty8
jetty8: /etc/jetty8 /usr/share/jetty8
~$ ls -al /usr/share/jetty8/
total 16
drwxr-xr-x 4 root root 4096 Feb 28 13:25 .
drwxr-xr-x 107 root root 4096 Feb 28 16:12 ..
lrwxrwxrwx 1 root root 20 Jul 30 2013 contexts -> /etc/jetty8/contexts
lrwxrwxrwx 1 root root 11 Jul 30 2013 etc -> /etc/jetty8
lrwxrwxrwx 1 root root 25 Jul 30 2013 javadoc -> ../doc/libjetty8-java/api
drwxr-xr-x 3 root root 4096 Feb 28 13:25 lib
lrwxrwxrwx 1 root root 15 Jul 30 2013 logs -> /var/log/jetty8
drwxr-xr-x 2 root root 4096 Feb 28 13:25 resources
lrwxrwxrwx 1 root root 40 Jul 30 2013 start.jar -> ../java/jetty8-start-8.1.3.v20120416.jar
lrwxrwxrwx 1 root root 23 Jul 30 2013 webapps -> /var/lib/jetty8/webapps
I'm using Scala 2.10.3, Lift 2.6-M2, SBT 0.13.1, Jetty 8.1.3.v20120416 and Java 8 on Linaro Ubuntu Server 13.10.
Stacktrace[excerpt]:
ERROR in ch.qos.logback.core.FileAppender[FILE] - openFile(console.devmode.log,true) call failed. java.io.FileNotFoundException: console.devmode.log (Permission denied)
at java.io.FileNotFoundException: console.devmode.log (Permission denied)
at at java.io.FileOutputStream.open(Native Method)
ERROR net.liftweb.db.StandardDBVendor - Unable to get database connection. url=jdbc:h2:lift_proto.db;AUTO_SERVER=TRUE
org.h2.jdbc.JdbcSQLException: IO Exception: "java.io.FileNotFoundException: /usr/share/jetty8/lift_proto.db.lock.db (Permission denied)"; "/usr/share/jetty8/lift_proto.db.lock.db" [90031-167]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:329) ~[h2-1.3.167.jar:1.3.167]
at org.h2.message.DbException.get(DbException.java:158) ~[h2-1.3.167.jar:1.3.167]
ERROR n.liftweb.http.provider.HTTPProvider - Failed to Boot! Your application may not run properly
java.lang.NullPointerException: Looking for Connection Identifier ConnectionIdentifier(lift) but failed to find either a JNDI data source with the name lift or a lift connection manager with the correct name
at net.liftweb.db.DB$$anonfun$newConnection$2.apply(DB.scala:190) ~[lift-db_2.10-2.6-M2.jar:2.6-M2]

Related

Java Spring boot on docker logging rolling policy doesn't limit amount of log archives

When I was running some test instances on multiple server I encountered a not enough space on some of the locations and as I inspected it was an issue with logger.
I use #Slf4j annotation to log.
Here is my configuration for logging:
# Logging
logging.level.root=INFO
logging.level.web=INFO
logging.logback.rollingpolicy.max-file-size=20MB
logging.file.name=logs/ims-app.log
logging.file.path=logs
logging.logback.rollingpolicy.max-history=7
Recent logs inside the docker:
/logs # ls -lah
total 7M
drwxr-xr-x 2 root root 4.0K Sep 22 17:40 .
drwxr-xr-x 1 root root 4.0K Sep 22 11:26 ..
-rw-r--r-- 1 root root 543.8K Sep 22 17:41 ims-app.log
-rw-r--r-- 1 root root 507.2K Sep 22 11:52 ims-app.log.2022-09-22.0.gz
-rw-r--r-- 1 root root 507.1K Sep 22 12:21 ims-app.log.2022-09-22.1.gz
-rw-r--r-- 1 root root 495.6K Sep 22 16:21 ims-app.log.2022-09-22.10.gz
-rw-r--r-- 1 root root 497.5K Sep 22 16:48 ims-app.log.2022-09-22.11.gz
-rw-r--r-- 1 root root 495.7K Sep 22 17:14 ims-app.log.2022-09-22.12.gz
-rw-r--r-- 1 root root 496.6K Sep 22 17:40 ims-app.log.2022-09-22.13.gz
-rw-r--r-- 1 root root 496.2K Sep 22 12:48 ims-app.log.2022-09-22.2.gz
-rw-r--r-- 1 root root 499.8K Sep 22 13:15 ims-app.log.2022-09-22.3.gz
-rw-r--r-- 1 root root 497.8K Sep 22 13:42 ims-app.log.2022-09-22.4.gz
-rw-r--r-- 1 root root 498.6K Sep 22 14:09 ims-app.log.2022-09-22.5.gz
-rw-r--r-- 1 root root 499.5K Sep 22 14:36 ims-app.log.2022-09-22.6.gz
-rw-r--r-- 1 root root 498.2K Sep 22 15:03 ims-app.log.2022-09-22.7.gz
-rw-r--r-- 1 root root 496.7K Sep 22 15:29 ims-app.log.2022-09-22.8.gz
-rw-r--r-- 1 root root 496.4K Sep 22 15:56 ims-app.log.2022-09-22.9.gz
After this issue I decided to move to a centralized logging with elk, but this issue will still continue on the java side. How do I limit how many log file for an instance. I still want to save recent logs as files, but in 30 days it exceeded 19GB (on the dev server) any suggestion on this?
You should not produce log files inside a running container. Just instruct log4j to write to standard output. This is a good practice.
If you need the files then map a volume and have the files saved in that folder. This way your container is not impacted and your only problem is the space on the host.

Docker and Java - FontConfiguration issue

We've got a Java application that generates word documents using a 3rd party (Asposee but I don't think it matters here). The app is built from a simple Docker file:
FROM openjdk:10-jdk-slim
COPY target/*.jar /opt/
CMD $JAVA_HOME/bin/java $JAVA_OPTS -jar /opt/*.jar
When we build the application locally (mvn package then docker build) and run the application inside k8s it works well.
However, when we build the image in our CI/CD pipeline with Jenkins we get a runtime exception when running through a specific process which apparently requires additional fonts:
Caused by: java.lang.NullPointerException: null
at java.desktop/sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1288)
at java.desktop/sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:225)
at java.desktop/sun.awt.FontConfiguration.init(FontConfiguration.java:107)
at java.desktop/sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:765)
at java.desktop/sun.font.SunFontManager$2.run(SunFontManager.java:440)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.desktop/sun.font.SunFontManager.<init>(SunFontManager.java:385)
at java.desktop/sun.awt.FcFontManager.<init>(FcFontManager.java:35)
at java.desktop/sun.awt.X11FontManager.<init>(X11FontManager.java:56)
In that case the project is buit in Jenkins, compiled by the docker image maven:3.5.4-jdk-10-slim.
I've checked both jar files (locally and from jenkins) and the class files are the same (as expected).
In both cases it's the same base image so I don't understand what could be the difference. Is something different in Docker when building locally vs inside another Docker container?
EDIT
We've looked into both docker images and found the following difference.
Since locally built image ls -l /usr/lib returns:
drwxr-xr-x 2 root root 4096 May 3 2017 X11
drwxr-xr-x 5 root root 4096 Apr 26 00:00 apt
drwxr-xr-x 2 root root 4096 May 26 08:31 binfmt.d
drwxr-xr-x 2 root root 4096 Jun 6 01:50 cgmanager
drwxr-xr-x 2 root root 4096 Jun 6 01:50 dbus-1.0
drwxr-xr-x 2 root root 4096 Jun 6 01:51 dconf
drwxr-xr-x 3 root root 4096 Jun 6 01:51 debug
drwxr-xr-x 3 root root 4096 Apr 20 10:08 dpkg
drwxr-xr-x 2 root root 4096 Jun 6 01:50 environment.d
drwxr-xr-x 3 root root 4096 Apr 25 04:56 gcc
drwxr-xr-x 2 root root 4096 Jun 6 01:51 glib-networking
drwxr-xr-x 2 root root 4096 Apr 26 00:00 init
drwxr-xr-x 1 root root 4096 Jun 6 01:51 jvm
drwxr-xr-x 3 root root 4096 Jun 6 01:50 kernel
lrwxrwxrwx 1 root root 20 Mar 4 09:49 libnih-dbus.so.1 -> libnih-dbus.so.1.0.0
-rw-r--r-- 1 root root 34824 Mar 4 09:49 libnih-dbus.so.1.0.0
lrwxrwxrwx 1 root root 15 Mar 4 09:49 libnih.so.1 -> libnih.so.1.0.0
-rw-r--r-- 1 root root 92184 Mar 4 09:49 libnih.so.1.0.0
drwxr-xr-x 3 root root 4096 Mar 29 19:47 locale
drwxr-xr-x 3 root root 4096 Jun 6 01:50 lsb
drwxr-xr-x 1 root root 4096 Jul 21 2017 mime
drwxr-xr-x 2 root root 4096 Jun 6 01:50 modprobe.d
drwxr-xr-x 2 root root 4096 May 26 08:31 modules-load.d
-rw-r--r-- 1 root root 198 Jan 13 23:36 os-release
drwxr-xr-x 3 root root 4096 Jun 6 01:51 ssl
drwxr-xr-x 1 root root 4096 Jun 6 01:50 systemd
drwxr-xr-x 2 root root 4096 Jun 6 01:50 sysusers.d
drwxr-xr-x 2 root root 4096 Jul 21 2017 tar
drwxr-xr-x 15 root root 4096 Feb 11 20:06 terminfo
drwxr-xr-x 1 root root 4096 Jun 6 01:50 tmpfiles.d
drwxr-xr-x 1 root root 4096 Apr 26 00:00 udev
drwxr-xr-x 1 root root 16384 Jun 6 01:51 x86_64-linux-gnu
But inside Jenkins built image ls -l /usr/lib returns:
drwxr-xr-x 5 root root 4096 Jun 25 00:00 apt
drwxr-xr-x 3 root root 4096 Jul 3 01:00 debug
drwxr-xr-x 3 root root 4096 Apr 20 10:08 dpkg
drwxr-xr-x 3 root root 4096 Jun 17 03:36 gcc
drwxr-xr-x 2 root root 4096 Jun 25 00:00 init
drwxr-xr-x 1 root root 4096 Jul 3 01:00 jvm
drwxr-xr-x 1 root root 4096 Jul 12 11:00 locale
drwxr-xr-x 3 root root 4096 Jul 3 01:00 lsb
drwxr-xr-x 1 root root 4096 May 16 07:47 mime
-rw-r--r-- 1 root root 198 Jan 13 23:36 os-release
drwxr-xr-x 3 root root 4096 Jul 3 01:00 ssl
drwxr-xr-x 3 root root 4096 Apr 20 10:08 systemd
drwxr-xr-x 2 root root 4096 May 16 07:47 tar
drwxr-xr-x 15 root root 4096 May 21 08:54 terminfo
drwxr-xr-x 2 root root 4096 Jun 25 00:00 tmpfiles.d
drwxr-xr-x 3 root root 4096 Jun 25 00:00 udev
drwxr-xr-x 2 root root 4096 May 3 2017 X11
drwxr-xr-x 1 root root 4096 Jul 3 01:00 x86_64-linux-gnu
This is really puzzling as I thought Docker would always produce the same image from identical Dockerfiles
With openjdk:8u111-jdk-alpine, installing dejavu fix the problem:
For example:
Dockerfile:
FROM openjdk:8u111-jdk-alpine
# Needed to fix 'Fontconfig warning: ignoring C.UTF-8: not a valid language tag'
ENV LANG en_GB.UTF-8
# JRE fails to load fonts if there are no standard fonts in the image; DejaVu is a good choice,
# see https://github.com/docker-library/openjdk/issues/73#issuecomment-207816707
RUN apk add --update ttf-dejavu && rm -rf /var/cache/apk/*
VOLUME /tmp
COPY /target/*.jar app.jar
ENTRYPOINT ["java","-Xmx100m","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
Just add the following in your Dockerfile
RUN apk add --no-cache fontconfig ttf-dejavu
Installing libfontconfig1 solved the problem for me (source):
RUN apt-get install -y libfontconfig1 && rm -rf /var/lib/apt/lists/*
I think we found the problem.
When running on Jenkins we use the docker:dind (Docker inside docker) Docker image to provide the docker command in the build. This image is based on Alpine linux. When running docker info we get the following:
On Mac:
Kernel Version: 4.9.87-linuxkit-aufs
Operating System: Docker for Mac
On Jenkins:
Kernel Version: 4.4.115-k8s
Operating System: Alpine Linux v3.7 (containerized)
Alpine linux must be missing those fonts. We fixed the problem by manually installing them in the Dockerfile:
RUN apt-get update \
&& apt-get install --assume-yes apt-utils \
&& apt-get install --assume-yes software-properties-common \
&& apt-get install --assume-yes dbus \
&& apt-get install --assume-yes cgmanager \
&& apt-get install --assume-yes glib-networking \
&& apt-get install --assume-yes libnih-dbus-dev \
&& apt-get install --assume-yes dconf-cli \
&& apt-get install --assume-yes fontconfig
Not sure this is the minimum required libraries but those did the trick :D
If you trying to do in Java/Spring boot , adding following in Dockerfile worked for me in java 11.
# Font packages to be added for java 11
RUN apk update \
&& apk add fontconfig \
&& apk add ttf-dejavu
RUN ln -s /usr/lib/libfontconfig.so.1 /usr/lib/libfontconfig.so && \
ln -s /lib/libuuid.so.1 /usr/lib/libuuid.so.1 && \
ln -s /lib/libc.musl-x86_64.so.1 /usr/lib/libc.musl-x86_64.so.1
ENV LD_LIBRARY_PATH /usr/lib
If you are running it on local with Docker Desktop and using docker file to create the image.
Please make changes in Dockerfile from FROM openjdk:8-jdk-alpine to FROM adoptopenjdk/openjdk11:ubi
Problem NullPointerException with fonts occurs when you use openjdk docker image in alpine version for example :
adoptopenjdk/openjdk11:jre-11.0.11_9-alpine.
You need change image to full version: adoptopenjdk/openjdk11:jre-11.0.11_9
I also got the same issue while running below command and restart app server resolved this issue.
Yup install fontconfig

WebLogic Console - No application files exist when redeploying application

When stopping/starting a deployment via the WebLogic Admin console, sometimes we get the following error:
Unable to access application source information in '/opt/product/oracle/local/managedservers/mydomain/servers/serverA/stage/apputil/apputil.war'
for application 'apputil’.
The specific error is: [Deployer:149158] No application files
exist at '/opt/product/oracle/local/managedservers/mydomain/servers/serverA/stage/apputil/apputil.war'
Yet, if I stop and start the managed server, the deployment appears to come back.
My question is, WHY do these war files disappear from the managed server seemingly randomly, while the server is running? This typically happens after we haven't touched a deployment for some time (6 months). Other war files for other deployments are there. It does not affect the running of the app, until we try to stop/start it.
This is what the filesystem looks like before and after.
[oracle#serverA stage]$ pwd;ls -alstr
/opt/product/oracle/local/managedservers/mydomain/servers/serverA/stage
total 20
4 drwxr-x--- 8 oracle dba 4096 Mar 19 2014 ..
4 drwxr----- 3 oracle dba 4096 Mar 19 2014 app-crypto-util
4 drwxr----- 2 oracle dba 4096 Mar 19 2014 appadmin
4 drwxr----- 2 oracle dba 4096 Mar 19 2014 appsm
4 drwxr----- 5 oracle dba 4096 May 1 15:29 .
[oracle#serverA stage]$ ls
appadmin app-crypto-util appsm
Restart managed server here...
[oracle#serverA stage]$ ls
appdmin app-crypto-util appsm apputil
[oracle#serverA stage]$ ls -alstr
total 24
4 drwxr-x--- 8 oracle dba 4096 Mar 19 2014 ..
4 drwxr----- 3 oracle dba 4096 Mar 19 2014 app-crypto-util
4 drwxr----- 2 oracle dba 4096 Mar 19 2014 appadmin
4 drwxr----- 2 oracle dba 4096 Mar 19 2014 appsm
4 drwxr----- 2 oracle dba 4096 Jun 25 14:35 apputil
4 drwxr----- 6 oracle dba 4096 Jun 25 14:35 .
[oracle#serverA stage]$ ls -alstr apputil/apputil.war
28660 -rw-r----- 1 oracle dba 29347298 Jun 25 14:35 apputil/apputil.war
This may happen when AdminServer & Managed Server are in different machines, or the war is being sent from a different machine to AS.
use arguments: -remote -upload
i.e.:
java weblogic.Deployer -adminurl t3://200.10.10.125:7001 -verbose -username weblogic -password welcome1 -deploy -targets WLCluster -name sample -remote -source sample.war -upload
Referring to the stage directory modification date, it appears this dir is created/edited when an event occur, maybe by a script, and if it is the case, the problem should come from that script when copying apps wars.
So in my POV when stopping a deployment, maybe weblogic stop the apputil managed server, wich delete the war from th stage dir, and when starting a deployment after stopping it, it does not start the specified managed server before, and try to redeploy all apps wich cause the exception.

Unable to find a javac compiler even when JDK present

I'm trying to run an Apache Hive web interface, so I downloaded the lastest version of ant (Ant 1.9.4), and when I execute the command to produce the hive.war file
ANT_LIB=/opt/ant/lib bin/hive --service hwi
I get the following error:
cp=/tmp/Jetty_0_0_0_0_9999_hive.hwi.0.10.0.war__hwi__ae9cmk/jsp
cp=null
work dir=/tmp/Jetty_0_0_0_0_9999_hive.hwi.0.10.0.war__hwi__ae9cmk/jsp
extension dir=/usr/lib/jvm/jdk1.7.0_65/jre/lib/ext:/usr/java/packages/lib/ext
srcDir=/tmp/Jetty_0_0_0_0_9999_hive.hwi.0.10.0.war__hwi__ae9cmk/jsp
compilerTargetVM=1.5
compilerSourceVM=1.5
include=org/apache/jsp/index_jsp.java
15/02/23 09:56:59 ERROR compiler.Compiler: Error compiling file: /tmp/Jetty_0_0_0_0_9999_hive.hwi.0.10.0.war__hwi__ae9cmk/jsp//org/apache/jsp/index_jsp.java [javac] warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
15/02/23 09:56:59 ERROR mortbay.log: /hwi/
Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "/usr/lib/jvm/jdk1.7.0_65/jre"
at org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory.getCompiler(CompilerAdapterFactory.java:130)
at org.apache.tools.ant.taskdefs.Javac.findSupportedFileExtensions(Javac.java:984)
at org.apache.tools.ant.taskdefs.Javac.scanDir(Javac.java:961)
at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:932)
at org.apache.jasper.compiler.AntCompiler.generateClass(AntCompiler.java:220)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:298)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:265)
I'm executing that code as root. My JAVA_HOME is correctly set at the .bashrc:
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_65
export HADOOP_LIBEXEC_DIR=/usr/lib/hadoop/libexec
export HADOOP_CONF_DIR=/etc/hadoop/conf
export PATH=$PATH:$JAVA_HOME/bin
and .bash_profile files:
.bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_65
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export PATH
I want to know why is Ant referencing the javac at "/usr/lib/jvm/jdk1.7.0_65/jre". Moreover, here is my JDK structure:
[root#ip-10-32-205-19 ~]# cd $JAVA_HOME
[root#ip-10-32-205-19 jdk1.7.0_65]# ls -l
total 19760
drwxr-xr-x. 2 root root 4096 Feb 23 04:09 bin
-r--r--r--. 1 root root 3339 Jun 17 2014 COPYRIGHT
drwxr-xr-x. 4 root root 4096 Jun 17 2014 db
drwxr-xr-x. 3 root root 4096 Jun 17 2014 include
drwxr-xr-x. 5 root root 4096 Jun 17 2014 jre
drwxr-xr-x. 5 root root 4096 Feb 23 04:09 lib
-r--r--r--. 1 root root 40 Jun 17 2014 LICENSE
drwxr-xr-x. 4 root root 4096 Jun 17 2014 man
-r--r--r--. 1 root root 114 Jun 17 2014 README.html
-rw-r--r--. 1 root root 499 Jun 17 2014 release
-rw-r--r--. 1 root root 19902785 Jun 17 2014 src.zip
-rw-r--r--. 1 root root 110114 Jun 16 2014 THIRDPARTYLICENSEREADME-JAVAFX.txt
-r--r--r--. 1 root root 173559 Jun 17 2014 THIRDPARTYLICENSEREADME.txt
which shows I have the JDK, and not only the JRE installed. I also took a look at similar questions, but none could solve my problem. The Java is 64bits, plus I also ran source for both .bashrc and .bash_profile.
The error message says:
Perhaps JAVA_HOME does not point to the JDK. It is currently set to
"/usr/lib/jvm/jdk1.7.0_65/jre"
However, your .bashrc has:
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_65
You likely need to run source ~/.bashrc in your Bash shell to reset JAVA_HOME to the root of your JDK installation. Then run Ant again.

LoadLibrary fails only when running from eclipse & tomcat

UnsatisfiedLinkError when trying to load Lingo library, on Linux 64 bit, in Java using
static{
System.loadLibrary("lingojni64");
}
After setting the LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/utcn11/lingo14/bin/linux64
when running from command line works fine;
when running from eclipse gives:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no lingojni64 in java.library.path
Already tried setting
System.setProperty("java.library.path", "/home/utcn11/lingo14/bin/linux64");
But same error occurs
when running from eclipse after setting the
-Djava.library.path="/home/utcn11/lingo14/bin/linux64"
The following error occurs:
Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/utcn11/lingo14/bin/linux64/liblingojni64.so.14.0: liblingo64.so.14: cannot open shared object file: No such file or directory
ls -l /home/utcn11/lingo14/bin/linux64
total 41084
lrwxrwxrwx 1 utcn11 utcn11 16 Sep 29 16:36 liblingo64.so -> liblingo64.so.14
lrwxrwxrwx 1 utcn11 utcn11 18 Sep 29 16:36 liblingo64.so.14 -> liblingo64.so.14.0
-rwxr-xr-x 1 utcn11 utcn11 2911124 Oct 15 2013 liblingo64.so.14.0
lrwxrwxrwx 1 utcn11 utcn11 19 Sep 29 16:36 liblingojni64.so -> liblingojni64.so.14
lrwxrwxrwx 1 utcn11 utcn11 21 Sep 29 16:36 liblingojni64.so.14 -> liblingojni64.so.14.0
-rwxr-xr-x 1 utcn11 utcn11 28809 Aug 22 2013 liblingojni64.so.14.0
same error occurs when running the webapp in tomcat
If run the project from Eclipse you can follow the next steps:
Right click on the project.
Go to Run as -> Run Configurations...
Go to the Environment tab.
Click on New to create a new environment variable.
Enter the name of the variable (LD_LIBARY_PATH) and its path.
Click OK, then Apply.

Categories

Resources