How to config the log file dir with logback? - logback

My environments:
ubuntu 18.04
openjdk 8
tomcat 8.5.50
logback 1.2.3
I put my logback.xml in webapps/ROOT/WEB-INF/classes, the file like:
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{yyyy-MM-dd HH:mm:ss} %-5level %logger - %msg%n</Pattern>
</layout>
</appender>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>/home/mc/shopping.log</file>
<append>true</append>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{yyyy-MM-dd HH:mm:ss} %-5level %logger - %msg%n</Pattern>
</layout>
</appender>
<root level="info">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>
When I start tomcat by bin/startup.sh, I can not find the file shopping.log in /home/mc.
What is my wrong please?

Related

Failed to execute goal org.eluder.coveralls:coveralls-maven-plugin:4.3.0:report on GitHub Actions

I'm trying to set up GitHub Actions for building a maven project with Coveralls on a public repository. For some reason it keeps failing with this error:
Failed to execute goal org.eluder.coveralls:coveralls-maven-plugin:4.3.0:report (default-cli) on project e-shop-manager: Build error: Either repository token or service with job id must be defined -> [Help 1]
I have looked through the coveralls documentation (both plugin and actions-side) to no avail.
Here is the yaml from Actions:
name: Java CI with Maven
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- name: Set up JDK 11
uses: actions/setup-java#v3
with:
distribution: 'adopt'
java-version: '11'
cache: 'maven'
- name: Build with Maven
run: mvn clean package jacoco:report coveralls:report
- name: Coveralls
uses: coverallsapp/github-action#master
with:
github-token: ${{ secrets.COVERALLS_TOKEN }}
where COVERALLS_TOKEN is my secret token, 100% sure it's been added as a repository secret.
Here is my maven project configuration too:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>it.unipd.mtss</groupId>
<artifactId>e-shop-manager</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>e-shop-manager</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<failsOnError>true</failsOnError>
<configLocation>checkstyle.xml</configLocation>
<consoleOutput>true</consoleOutput>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>checkstyle</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>4.3.0</version>
</plugin>
</plugins>
</build>
</project>
I couldn't find anything elsewhere other than documentation, since I have pretty much copied configs from docs.

Multiple mysql image not working in Springboot and docker

I'm new on Springboot and docker.
I'm trying to create three different microservices and load them into docker.
Two of them start correctly while the last one returns the following error:
Caused by: com.mysql.cj.exceptions.CJException: Access denied for user 'db_user'#'%' to database 'PaymentDB'
I can't find the error. The configuration of the three microservices are exactly the same (sometimes I copied and paste the similar code and changed only the name for example from Catalog to Payment. Can You suggest me something?
This is the application.properties:
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://${PM_DATASOURCE_HOST}:${DATASOURCE_PORT}/${PM_DATASOURCE_NAME}?autoReconnect=true
spring.datasource.username=${DATASOURCE_USER}
spring.datasource.password=${DATASOURCE_PASSWORD}
spring.kafka.bootstrap-servers=kafka:9092
kafkaTopic=payment-topic
This is the .env :
DB_DATABASE_PAYMENT=PaymentDB
DB_HOST_PAYMENT=paymentmysqldb
DB_DATABASE_USER=UserDB
DB_HOST_USER=usermysqldb
DB_DATABASE_CATALOG=CatalogDB
DB_HOST_CATALOG=catalogmysqldb
DB_USER=db_user
DB_PASSWORD=alx2022
DB_ROOT_PASSWORD=user
DB_PORT=3306
This is the docker-compose.yml
version: '3.4'
x-common-variables: &common-variables
DATASOURCE_USER: ${DB_USER}
DATASOURCE_PASSWORD: ${DB_PASSWORD}
DATASOURCE_PORT: ${DB_PORT}
services:
paymentmysqldb:
container_name: paymentmysqldb
image: mysql
ports:
- "3313:3306"
environment:
- MYSQL_DATABASE=${DB_DATABASE_PAYMENT}
- MYSQL_USER=${DB_USER}
- MYSQL_PASSWORD=${DB_PASSWORD}
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
volumes:
- paymentstorage:/var/lib/mysql
usermysqldb:
container_name: usermysqldb
image: mysql
ports:
- "3311:3306"
environment:
- MYSQL_DATABASE=${DB_DATABASE_USER}
- MYSQL_USER=${DB_USER}
- MYSQL_PASSWORD=${DB_PASSWORD}
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
volumes:
- userstorage:/var/lib/mysql
catalogmysqldb:
container_name: catalogmysqldb
image: mysql
ports:
- "3312:3306"
environment:
- MYSQL_DATABASE=${DB_DATABASE_CATALOG}
- MYSQL_USER=${DB_USER}
- MYSQL_PASSWORD=${DB_PASSWORD}
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
volumes:
- catalogstorage:/var/lib/mysql
paymentmanager:
container_name: paymentmanager
image: arausa/paymentimage
build:
context: .
dockerfile: MicroServices/PaymentManager/Dockerfile
depends_on:
- paymentmysqldb
ports:
- "3333:8080"
restart: always
environment:
<<: *common-variables
PM_DATASOURCE_HOST: ${DB_HOST_PAYMENT}
PM_DATASOURCE_NAME: ${DB_DATABASE_PAYMENT}
usermanager:
container_name: usermanager
image: arausa/userimage
build:
context: .
dockerfile: MicroServices/UserManager/Dockerfile
depends_on:
- usermysqldb
ports:
- "1111:8080"
restart: always
environment:
<<: *common-variables
UM_DATASOURCE_HOST: ${DB_HOST_USER}
UM_DATASOURCE_NAME: ${DB_DATABASE_USER}
catalogmanager:
container_name: catalogmanager
image: arausa/catalogimage
build:
context: .
dockerfile: MicroServices/CatalogManager/Dockerfile
depends_on:
- catalogmysqldb
ports:
- "2222:8080"
restart: always
environment:
<<: *common-variables
CM_DATASOURCE_HOST: ${DB_HOST_CATALOG}
CM_DATASOURCE_NAME: ${DB_DATABASE_CATALOG}
#kafka usa zookeeper tiene traccia dei broker, topologia della network e info per la sincronizzazione
zookeeper:
image: wurstmeister/zookeeper
#identifica il broker kafka
kafka:
image: wurstmeister/kafka
ports:
- "9092:9092" #porta di default per il broker kafka
environment:
KAFKA_ADVERTISED_HOST_NAME: kafka
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 #serve a dire dove sta girando zookeeper
volumes:
userstorage:
catalogstorage:
paymentstorage:
This is the pom.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.4</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>PaymentManager</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>PaymentManager</name>
<description>PaymentManager</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>
This is the docker file :
FROM maven:3-openjdk-17-slim as builder
WORKDIR /project
COPY MicroServices/PaymentManager/ .
RUN mvn package
FROM openjdk:17-alpine
WORKDIR /app
COPY --from=builder /project/target/PaymentManager-0.0.1-SNAPSHOT.jar ./PaymentManager.jar
CMD java -jar PaymentManager.jar
Seems like your application.properties has some error.
spring.datasource.username=${DATASOURCE_USER}
spring.datasource.password=${DATASOURCE_PASSWORD}
these env variables aren't defined or exported from anywhere.
I solved in a strange way.
I modified the word "Payment" with the word "pay" everywhere and it magically works. Even if I don't understand the reason

Docker-compose deploys my app, but the init.sql script data is not loaded

I am working on Windows, Docker Desktop version 19.03.1, build 74b1e89 and docker-compose version 1.24.1, build 4667896b
My docker machine is hyper-v
I am trying to initialize the mysql database docker container for the deploy of my spring jpa app.
I have a docker-compose.yml file with two services: mysql-docker-container and spring-jpa-app. This file is in /resources/ folder inside project.
The init.sql file is located there too.
I am locating the init.sql in the same folder as application.properties because I read that with this configuration:
spring.datasource.initialization-mode=always
spring.datasource.type=com.mysql.jdbc.jdbc2.optional.MysqlDataSource
spring.jpa.hibernate.ddl-auto=none
and excluding HikariCP:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</exclusion>
</exclusions>
</dependency>
it would load all database and data in init.sql
But instead, I get Communications link failure but still starts the application.
Postman works and gives respones but without the data that i want to load, results empty.
That is why I included the healthcheck to check if mysql container is "healthy" but I am not sure that is what I need.
Also, I tried to enter the mysql container (when app started after docker-compose up --build) in another git bash as administrator but I cannot access to it because docker ps -a is empty
docker-compose-yml
version: '3.7'
services:
mysql-docker-container:
image: mysql
networks:
- mired
container_name: mysql-docker-container
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=database
- MYSQL_USER=user
- MYSQL_PASSWORD=user
ports:
- 2012:3306
volumes:
- c:/Users/User/Documents/project/src/main/resources/db/:/docker-entrypoint-initdb.d
tty: true
healthcheck:
test: ["CMD-SHELL", 'mysqladmin ping']
interval: 10s
timeout: 2s
retries: 10
spring-jpa-app:
build:
context: .
dockerfile: Dockerfile
networks:
- mired
container_name: spring-jpa-app
links:
- mysql-docker-container:mysql-docker-container
depends_on:
- mysql-docker-container
ports:
- 8087:8080
tty: true
networks:
mired:
Dockerfile
FROM java:8
VOLUME /tmp
EXPOSE 8080
ADD app.jar app.jar
ENTRYPOINT ["java","-jar","app.jar"]
application.properties
server.port=8080
spring.datasource.url=jdbc:mysql://172.18.67.41:3306/database?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&autoReconnect=true&useSSL=false
spring.datasource.username=user
spring.datasource.password=user
spring.datasource.initialization-mode=always
spring.datasource.type=com.mysql.jdbc.jdbc2.optional.MysqlDataSource
spring.jpa.hibernate.ddl-auto=none
logging.file=log/log.log
logging.level.org.springframework=info
logging.level.orghibernate=info
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.app</groupId>
<artifactId>app</artifactId>
<packaging>jar</packaging>
<name>app</name>
<description>Application</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>auth0-spring-security-api</artifactId>
<version>1.0.0-rc.3</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180813</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
spring-jpa-app | 2019-08-05 10:23:44.920 ERROR 1 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
spring-jpa-app |
spring-jpa-app | com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
spring-jpa-app |
spring-jpa-app | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

Mysql connection error in wso2 apim/identity server docker

I have 3 dockerfiles for WSO2 apim, identity server, and mysql. using docker-compose to run these. The corresponding docker-compose.yml is given as below:-
# docker-compose version
version: "3.7"
# services/containers to be run
services:
wso2am:
build: ./apim
image: wso2am:2.6.0
ports:
- "9443:9443"
links:
- mysql-db
- wso2is-km
wso2is-km:
build: ./is-as-km
image: wso2is-km:5.7.0
ports:
- "9444:9444"
links:
- mysql-db
mysql-db:
build: ./mysql
image: mysql:5.7.26
ports:
- "3306:3306"
- "33060:33060"
When running without changing h2 database to mysql Identity server/ apim works fine at ports 9444/9443 respectively. Also in mysql docker created regdb/apidb sql databases from the datascripts folder in apim/identity server.
# Derived from official mysql image (our base image)
FROM mysql:5.7
MAINTAINER Abhilash K R <abhilash.kr#aot-technologies.com>
ENV MYSQL_ROOT_PASSWORD root
# Add a user
ENV MYSQL_USER wso2carbon
ENV MYSQL_PASSWORD wso2carbon
# Add the content of the sql-scripts/ directory to your image
# All scripts in docker-entrypoint-initdb.d/ are automatically
COPY sql-scripts/ /docker-entrypoint-initdb.d
# expose ports
EXPOSE 3306 33060
Added jdbc driver and added new db url as below:
<datasource>
<name>WSO2_CARBON_DB</name>
<description>The datasource used for registry and user manager</description>
<jndiConfig>
<name>jdbc/WSO2CarbonDB</name>
</jndiConfig>
<definition type="RDBMS">
<configuration>
<url>jdbc:mysql://localhost:3306/regdb</url>
<username>wso2carbon</username>
<password>wso2carbon</password>
<driverClassName>com.mysql.cj.jdbc.Driver</driverClassName>
<maxActive>50</maxActive>
<maxWait>60000</maxWait>
<testOnBorrow>true</testOnBorrow>
<validationQuery>SELECT 1</validationQuery>
<validationInterval>30000</validationInterval>
<defaultAutoCommit>true</defaultAutoCommit>
</configuration>
</definition>
</datasource>
Getting the error as below:
Thinking the error is at the url jdbc:mysql://localhost:3306/regdb , tried to give localhost/ip of the dockerhost also still didn0t work.
Try to change the mysql connection string as below -
<url>jdbc:mysql:jdbc:mysql://mysql-db:3306/regdb</url>
In compose, services are reachable by their name itself. No need to use links etc. You can use depends_on or service_healthy in case you have interdependent services.
Ref - https://docs.docker.com/compose/compose-file/compose-file-v2/#depends_on
This is due to the error when connecting to user database. Could you verify whether the username and password configured for this database is correct?

Running Javadoc and Sonar in Hudson

?I am trying to run SOnar and Javadoc together using Maven3. However it seems that both of them call a clean gaol before running javadoc:javadoc and sonar:sonar. Due to this the output of one of them is lost. My pom entries are
<build>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>2.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.5</version>
<configuration>
<threshold>Low</threshold>
<effort>Max</effort>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version>
</plugin>
</plugins>
</reporting>
Is there anything wrong with my maven entries. Can someone clarify how can I run both the goals to gether.