Java

Jetty’s start.jar forks a new JVM to run the app if logback module is enabled

Jetty is too smart. If there is any JVM option provided, Jetty will spawn a new JVM instance to do the real work, even if you don’t use “–exec” option in start.ini And jetty’s logback module introduces a JVM option. See here You will see: -Dorg.eclipse.jetty.util.log.class?=org.eclipse.jetty.util.log.Slf4jLog So does it matter? It matters a lot because …

Jetty’s start.jar forks a new JVM to run the app if logback module is enabled Read More »

Code snippet: Swagger + Spring Boot

compile ‘io.springfox:springfox-swagger2:2.9.2’ compile ‘io.springfox:springfox-swagger-ui:2.9.2’ /** See https://www.baeldung.com/swagger-2-documentation-for-spring-rest-api */ @Configuration @EnableSwagger2 public class SwaggerConfig { @Value(“${enable.swagger}”) //You may want to disabled it in PROD boolean enableSwagger; @Bean public Docket api() { Docket api = new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage(“your.package”)) .paths(PathSelectors.any()) .build(); ApiInfo apiInfo = new ApiInfoBuilder() .version(“xxx”) .description(“xxx”) .termsOfServiceUrl(“xxx”) .title(“Xxx Doc”) .build(); api.useDefaultResponseMessages(false).apiInfo(apiInfo); api.enable(enableSwagger); return api; } …

Code snippet: Swagger + Spring Boot Read More »

Read process output in Java without hanging the main thread

/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * “License”); you may not use this …

Read process output in Java without hanging the main thread Read More »

Gradle upload a custom-generated jar file to Nexus

Do this: apply plugin: ‘maven-publish’ publishing { publications { maven( MavenPublication ) { artifact theTaskThatGeneratesJar } } repositories { maven { def releasesRepoUrl = http://…/repositories/releases/’ def snapshotsRepoUrl = ‘http://…/repositories/snapshots/’ url = version.endsWith(‘SNAPSHOT’) ? snapshotsRepoUrl : releasesRepoUrl credentials { username ‘xxx’ password ‘xxx’ } } } }

Quick log4j set up

<!– pom.xml –> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.7</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.7</version> </dependency> <!– src/main/resources/log4j.xml –> <?xml version=”1.0″ encoding=”UTF-8″?> <!DOCTYPE log4j:configuration SYSTEM “log4j.dtd”> <log4j:configuration xmlns:log4j=”http://jakarta.apache.org/log4j/”> <appender name=”my-file-appender” class=”org.apache.log4j.FileAppender”> <param name=”file” value=”some.file” /> <param name=”append” value=”true” /> <param name=”encoding” value=”UTF-8″ /> <layout class=”org.apache.log4j.PatternLayout”> <param name=”ConversionPattern” value=”%d %t %-5p %c – %m%n” /> </layout> </appender> <appender name=”console” …

Quick log4j set up Read More »