I am practicing with Kotlin and wanting to run a lightweight Rest application. I have experience with Undertow with Jersey, Jackson and Weld CDI in Java.
I wrote the minimum to startup the web container and it's running fine in IntelliJ.
Altough, when I try to run the jar-with-dependencies with java -jar app-with-dependencies.jar, I get errors.
Main class:
package nl.orhun.samplerestapp
import io.undertow.Handlers
import io.undertow.Undertow
import io.undertow.servlet.Servlets
import io.undertow.servlet.Servlets.servlet
import nl.orhun.samplerestapp.config.JerseyConfig
import org.glassfish.jersey.servlet.ServletContainer
import org.jboss.weld.environment.servlet.Listener
fun main() {
val servletBuilder = Servlets.deployment()
servletBuilder.setClassLoader(ClassLoader.getSystemClassLoader())
.setContextPath("/app")
.setDeploymentName("app.war")
.addListener(Servlets.listener(Listener::class.java))
.addServlets(
servlet("jerseyServlet", ServletContainer::class.java)
.setLoadOnStartup(1)
.addInitParam("javax.ws.rs.Application", JerseyConfig::class.java.name)
.addMapping("/rest/*")
)
val manager = Servlets.defaultContainer().addDeployment(servletBuilder)
manager.deploy()
val path = Handlers.path(Handlers.redirect("/app"))
.addPrefixPath("/app", manager.start())
val server = Undertow.builder()
.addHttpListener(8090, "localhost")
.setHandler(path)
.build()
server.start()
}
Error:
$ java -jar target/nl.orhun.samplerestapi-1.0-SNAPSHOT-jar-with-dependencies.jar
Mar 06, 2019 9:04:48 PM org.jboss.weld.environment.servlet.Listener contextInitialized
INFO: WELD-ENV-001007: Initialize Weld using ServletContextListener
Mar 06, 2019 9:04:48 PM org.jboss.weld.bootstrap.WeldStartup <clinit>
INFO: WELD-000900: 2.4.8 (Final)
Mar 06, 2019 9:04:48 PM org.jboss.weld.bootstrap.WeldStartup startContainer
INFO: WELD-000101: Transactional services not available. Injection of #Inject UserTransaction not available. Transactional observers will be invoked synchronously.
Mar 06, 2019 9:04:49 PM org.jboss.weld.bootstrap.MissingDependenciesRegistry handleResourceLoadingException
INFO: WELD-000119: Not generating any bean definitions from org.glassfish.hk2.osgiresourcelocator.ServiceLoaderImpl because of underlying class loading error: Type org.osgi.framework.BundleListener not found. If this is unexpected, enable DEBUG logging to see the full error.
Mar 06, 2019 9:04:49 PM org.jboss.weld.bootstrap.MissingDependenciesRegistry handleResourceLoadingException
INFO: WELD-000119: Not generating any bean definitions from org.jboss.logging.JBossLogManagerLogger because of underlying class loading error: Type org.jboss.logmanager.Level not found. If this is unexpected, enable DEBUG logging to see the full error.
Mar 06, 2019 9:04:49 PM org.jboss.weld.bootstrap.MissingDependenciesRegistry handleResourceLoadingException
INFO: WELD-000119: Not generating any bean definitions from org.jboss.weld.injection.spi.helpers.ForwardingJpaInjectionServices because of underlying class loading error: Type javax.persistence.EntityManager not found. If this is unexpected, enable DEBUG logging to see the full error.
Mar 06, 2019 9:04:49 PM org.jboss.weld.bootstrap.MissingDependenciesRegistry handleResourceLoadingException
INFO: WELD-000119: Not generating any bean definitions from io.undertow.servlet.osgi.Activator because of underlying class loading error: Type org.osgi.framework.BundleActivator not found. If this is unexpected, enable DEBUG logging to see the full error.
Mar 06, 2019 9:04:49 PM org.jboss.weld.bootstrap.MissingDependenciesRegistry handleResourceLoadingException
INFO: WELD-000119: Not generating any bean definitions from org.jboss.weld.jsf.FacesUrlTransformer because of underlying class loading error: Type javax.faces.context.FacesContext not found. If this is unexpected, enable DEBUG logging to see the full error.
Mar 06, 2019 9:04:49 PM org.jboss.weld.bootstrap.MissingDependenciesRegistry handleResourceLoadingException
INFO: WELD-000119: Not generating any bean definitions from org.glassfish.jersey.internal.OsgiRegistry$OsgiServiceFinder because of underlying class loading error: Type org.osgi.framework.SynchronousBundleListener not found. If this is unexpected, enable DEBUG logging to see the full error.
Mar 06, 2019 9:04:49 PM org.jboss.weld.bootstrap.MissingDependenciesRegistry handleResourceLoadingException
INFO: WELD-000119: Not generating any bean definitions from org.glassfish.jersey.server.internal.scanning.PackageNamesScanner$1 because of underlying class loading error: Type org.osgi.framework.SynchronousBundleListener not found. If this is unexpected, enable DEBUG logging to see the full error.
Mar 06, 2019 9:04:49 PM org.jboss.weld.bootstrap.MissingDependenciesRegistry handleResourceLoadingException
<.... truncated...>
Exception in thread "main" java.lang.RuntimeException: org.jboss.weld.exceptions.DeploymentException: Malformed class name
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:252)
at nl.orhun.samplerestapp.MainKt.main(Main.kt:26)
at nl.orhun.samplerestapp.MainKt.main(Main.kt)
Caused by: org.jboss.weld.exceptions.DeploymentException: Malformed class name
at org.jboss.weld.executor.AbstractExecutorServices.checkForExceptions(AbstractExecutorServices.java:66)
at org.jboss.weld.executor.AbstractExecutorServices.invokeAllAndCheckForExceptions(AbstractExecutorServices.java:43)
at org.jboss.weld.executor.AbstractExecutorServices.invokeAllAndCheckForExceptions(AbstractExecutorServices.java:51)
at org.jboss.weld.bootstrap.ConcurrentBeanDeployer.addClasses(ConcurrentBeanDeployer.java:58)
at org.jboss.weld.bootstrap.BeanDeployment.createClasses(BeanDeployment.java:224)
at org.jboss.weld.bootstrap.WeldStartup.startInitialization(WeldStartup.java:398)
at org.jboss.weld.bootstrap.WeldBootstrap.startInitialization(WeldBootstrap.java:76)
at org.jboss.weld.environment.servlet.WeldServletLifecycle.initialize(WeldServletLifecycle.java:191)
at org.jboss.weld.environment.servlet.Listener.contextInitialized(Listener.java:125)
at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:187)
at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:216)
at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:185)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:250)
... 2 more
Caused by: java.lang.InternalError: Malformed class name
at java.lang.Class.getSimpleBinaryName(Unknown Source)
at java.lang.Class.isMemberClass(Unknown Source)
at org.jboss.weld.util.reflection.Reflections.getNesting(Reflections.java:138)
at org.jboss.weld.annotated.slim.backed.BackedAnnotatedConstructor.initParameters(BackedAnnotatedConstructor.java:50)
at org.jboss.weld.annotated.slim.backed.BackedAnnotatedConstructor.initParameters(BackedAnnotatedConstructor.java:28)
at org.jboss.weld.annotated.slim.backed.BackedAnnotatedCallable.<init>(BackedAnnotatedCallable.java:34)
at org.jboss.weld.annotated.slim.backed.BackedAnnotatedConstructor.<init>(BackedAnnotatedConstructor.java:38)
at org.jboss.weld.annotated.slim.backed.BackedAnnotatedConstructor.of(BackedAnnotatedConstructor.java:32)
at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$BackedAnnotatedConstructors.computeValue(BackedAnnotatedType.java:168)
at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$BackedAnnotatedConstructors.computeValue(BackedAnnotatedType.java:161)
at org.jboss.weld.util.LazyValueHolder.get(LazyValueHolder.java:58)
at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$EagerlyInitializedLazyValueHolder.<init>(BackedAnnotatedType.java:157)
at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$BackedAnnotatedConstructors.<init>(BackedAnnotatedType.java:161)
at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$BackedAnnotatedConstructors.<init>(BackedAnnotatedType.java:161)
at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType.<init>(BackedAnnotatedType.java:62)
at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType.of(BackedAnnotatedType.java:46)
at org.jboss.weld.resources.ClassTransformer$TransformClassToBackedAnnotatedType.apply(ClassTransformer.java:80)
at org.jboss.weld.resources.ClassTransformer$TransformClassToBackedAnnotatedType.apply(ClassTransformer.java:77)
at org.jboss.weld.util.cache.ReentrantMapBackedComputingCache$1.apply(ReentrantMapBackedComputingCache.java:55)
at org.jboss.weld.util.cache.ReentrantMapBackedComputingCache$1.apply(ReentrantMapBackedComputingCache.java:51)
at org.jboss.weld.util.cache.ReentrantMapBackedComputingCache.getValue(ReentrantMapBackedComputingCache.java:64)
at org.jboss.weld.util.cache.ReentrantMapBackedComputingCache.getCastValue(ReentrantMapBackedComputingCache.java:80)
at org.jboss.weld.resources.ClassTransformer.getBackedAnnotatedType(ClassTransformer.java:175)
at org.jboss.weld.resources.ClassTransformer.getBackedAnnotatedType(ClassTransformer.java:192)
at org.jboss.weld.bootstrap.AnnotatedTypeLoader.loadAnnotatedType(AnnotatedTypeLoader.java:83)
at org.jboss.weld.bootstrap.AnnotatedTypeLoader.loadAnnotatedType(AnnotatedTypeLoader.java:62)
at org.jboss.weld.bootstrap.BeanDeployer.addClass(BeanDeployer.java:94)
at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$1.doWork(ConcurrentBeanDeployer.java:61)
at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$1.doWork(ConcurrentBeanDeployer.java:58)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:62)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:55)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -6
at java.lang.String.substring(Unknown Source)
... 35 more
Build segment of the pom:
<build>
<plugins>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/test/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>nl.orhun.samplerestapp.MainKt</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I am thinking that this has something to do with how I create the jar file but I'm not sure.
Why is my application not starting up when I run the jar file?
I'm not using Undertow, but I use Weld SE in a servlet setup running on Jetty and ran into the same issue as you, it seems like. I had some luck with excluding kotlin-packages from the bean discovery scan in my beans.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="all"
version="1.1">
<scan>
...
<exclude name="kotlin.**" />
<exclude name="kotlinx.**" />
</scan>
</beans>
I tried debugging the issue, and for me, the java.lang.InternalError: Malformed class name originated from the Java Class.getSimpleBinaryName called on some lambda in the body of kotlin.coroutines.CoroutineContext.plus, named kotlin.coroutines.CoroutineContext$plus$1 that apparently has the enclosing class kotlin.coroutines.CoroutineContext$DefaultImpls which is 6 characters longer than the lambda class name, causing an IndexOutOfBoundsException when trying to substring the lambda name with the length of the enclosing class name to get the simple name of the lambda. This may be seen as a bug in the way Kotlin names/types lambdas. A least with respect to reflection.
I also tried replicating the problem by creating this interface:
interface Foo {
fun fooBar(operation: (Foo) -> Foo): Foo
fun plus(foo: Foo): Foo = fooBar { f -> f.plus(f) }
}
And it causes the same problem (with or without operator before fun). Making Foo a class, and implementing fooBar, makes the problem go away though. Don't know why.
Using for instance let in the body of Foo.plus didn't cause any problems. Probably because let is inlined. So if you can stay away from using un-inlined lambdas in interface function bodies, you might be okay. And you can always put the interface causing problems in a package of its own and exclude this from being scanned, if you are not going to inject it. Hopefully this problem is not widespread.
Hope this helped, despite not being an Undertow-specific answer!
EDIT: You can add the #JvmDefault (https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.jvm/-jvm-default/index.html) annotation to an implemented function in an interface to create default method (Java 8 feature) compatible bytecode, and hence eliminate the problem described above. Note that you then have to specify the -Xjvm-default=enable or -Xjvm-default=compatibility compiler argument. More light is shed over #JvmDefault in this article: https://realjenius.com/2018/06/29/jvm-default/.
Related
I'm getting some inconsistent behaviour in my unit test logging when either:
Running tests via IntelliJ's Run interface
Running tests via mvn test
I really want to see the following log statements when running mvn test, however they do not seem to be visible:
May 12, 2022 12:00:13 PM org.junit.jupiter.api.ClassOrderer$Random <clinit>
CONFIG: ClassOrderer.Random default seed: 155513463168987
May 12, 2022 12:00:13 PM org.junit.jupiter.engine.config.InstantiatingConfigurationParameterConverter logSuccessMessage
CONFIG: Using default class orderer 'org.junit.jupiter.api.ClassOrderer$Random' set via the 'junit.jupiter.testclass.order.default' configuration parameter.
May 12, 2022 12:00:13 PM org.junit.jupiter.api.MethodOrderer$Random <clinit>
CONFIG: MethodOrderer.Random default seed: 155513483010989
Inside my pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.config.file>
${project.build.testOutputDirectory}/logging.properties
</java.util.logging.config.file>
</systemPropertyVariables>
</configuration>
</plugin>
Contents of src/test/resources/logging.properties:
.level=CONFIG
.handlers=java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level=CONFIG
When running tests via IntelliJ's Run interface, I can see the following output, with the desired logs towards the bottom:
/Users/ian.jones/Library/Java/JavaVirtualMachines/openjdk-17.0.2/Contents/Home/bin/java -ea -Djava.util.logging.config.file=/Users/ian.jones/Development/my-app/target/test-classes/logging.properties -Didea.test.cyclic.buffer.size=1048576 -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=61653:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 -classpath [omitted for brevity] com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit5 com.myorg.OpenApiDocsGeneratorTest
May 12, 2022 12:00:13 PM org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry loadTestEngines
CONFIG: Discovered TestEngines with IDs: [junit-jupiter (group ID: org.junit.jupiter, artifact ID: junit-jupiter-engine, version: 5.8.2, location: jar:file:/Users/ian.jones/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.8.2/junit-jupiter-engine-5.8.2.jar!/org/junit/jupiter/engine/JupiterTestEngine.class)]
May 12, 2022 12:00:13 PM org.junit.platform.launcher.core.ServiceLoaderRegistry load
CONFIG: Loaded PostDiscoveryFilter instances: []
May 12, 2022 12:00:13 PM org.junit.platform.launcher.core.ServiceLoaderRegistry load
CONFIG: Loaded LauncherDiscoveryListener instances: []
May 12, 2022 12:00:13 PM org.junit.platform.launcher.core.ServiceLoaderRegistry load
CONFIG: Loaded TestExecutionListener instances: [org.junit.platform.launcher.listeners.UniqueIdTrackingListener#2781e022]
May 12, 2022 12:00:13 PM org.junit.platform.launcher.core.LauncherConfigurationParameters loadClasspathResource
CONFIG: Loading JUnit Platform configuration parameters from classpath resource [file:/Users/ian.jones/Development/my-app/target/test-classes/junit-platform.properties].
May 12, 2022 12:00:13 PM org.junit.platform.launcher.core.ServiceLoaderRegistry load
CONFIG: Loaded LauncherSessionListener instances: []
May 12, 2022 12:00:13 PM org.junit.platform.launcher.core.LauncherConfigurationParameters loadClasspathResource
CONFIG: Loading JUnit Platform configuration parameters from classpath resource [file:/Users/ian.jones/Development/my-app/target/test-classes/junit-platform.properties].
May 12, 2022 12:00:13 PM org.junit.jupiter.api.ClassOrderer$Random <clinit>
CONFIG: ClassOrderer.Random default seed: 155513463168987
May 12, 2022 12:00:13 PM org.junit.jupiter.engine.config.InstantiatingConfigurationParameterConverter logSuccessMessage
CONFIG: Using default class orderer 'org.junit.jupiter.api.ClassOrderer$Random' set via the 'junit.jupiter.testclass.order.default' configuration parameter.
May 12, 2022 12:00:13 PM org.junit.jupiter.api.MethodOrderer$Random <clinit>
CONFIG: MethodOrderer.Random default seed: 155513483010989
May 12, 2022 12:00:13 PM org.junit.jupiter.engine.config.InstantiatingConfigurationParameterConverter logSuccessMessage
CONFIG: Using default method orderer 'org.junit.jupiter.api.MethodOrderer$Random' set via the 'junit.jupiter.testmethod.order.default' configuration parameter.
However, when running mvn clean install, the logs which are important to me do not appear:
[INFO] --- maven-surefire-plugin:3.0.0-M5:test (default-test) # my-app ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[ERROR] May 12, 2022 12:10:06 PM org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry loadTestEngines
[ERROR] CONFIG: Discovered TestEngines with IDs: [junit-jupiter (group ID: org.junit.jupiter, artifact ID: junit-jupiter-engine, version: 5.8.2, location: jar:file:/Users/ian.jones/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.8.2/junit-jupiter-engine-5.8.2.jar!/org/junit/jupiter/engine/JupiterTestEngine.class)]
[ERROR] May 12, 2022 12:10:06 PM org.junit.platform.launcher.core.ServiceLoaderRegistry load
[ERROR] CONFIG: Loaded PostDiscoveryFilter instances: []
[ERROR] May 12, 2022 12:10:06 PM org.junit.platform.launcher.core.ServiceLoaderRegistry load
[ERROR] CONFIG: Loaded LauncherDiscoveryListener instances: []
[ERROR] May 12, 2022 12:10:06 PM org.junit.platform.launcher.core.ServiceLoaderRegistry load
[ERROR] CONFIG: Loaded TestExecutionListener instances: [org.junit.platform.launcher.listeners.UniqueIdTrackingListener#76c3e77a]
[ERROR] May 12, 2022 12:10:06 PM org.junit.platform.launcher.core.LauncherConfigurationParameters loadClasspathResource
[ERROR] CONFIG: Loading JUnit Platform configuration parameters from classpath resource [file:/Users/ian.jones/Development/my-app/target/test-classes/junit-platform.properties].
[ERROR] May 12, 2022 12:10:06 PM org.junit.platform.launcher.core.ServiceLoaderRegistry load
[ERROR] CONFIG: Loaded LauncherSessionListener instances: []
[INFO] Running ...
I have tried changing the version of maven-surefire-plugin to 3.0.0-M4 or 3.0.0-M6 but in both cases, this results in all the CONFIG logs disappearing from the output.
I have also tried explicitly setting the handlers for the classes in question, e.g.:
org.junit.jupiter.api.MethodOrderer$Random.handlers=java.util.logging.ConsoleHandler
But all this does is result in duplicate output log lines when running tests with Run, and doesn't change the output when running tests with mvn test.
Clearly it's partially working in that it is reading logging.config in both cases (if I remove this file, all CONFIG logs disappear when running mvn test) - but I have no idea why the behaviour is different, or how to fix that.
EDIT: Minimal pom.xml file
Here's a minimal pom.xml demonstrating the issue (I'm using Maven 3.8.5)
<?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>org.example</groupId>
<artifactId>surefire-problem-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.config.file>
${project.build.testOutputDirectory}/logging.properties
</java.util.logging.config.file>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
Introduction
Let's consider the following versions as the current versions:
Maven Surefire Plugin 3.0.0-M7.
JUnit 5.8.2.
Root cause analysis
Analysis
Maven Surefire Plugin uses its JUnitPlatformProvider class. It may be observed in the output right before the «Tests» section:
<…>
[INFO] --- maven-surefire-plugin:3.0.0-M7:test (default-test) # the-project ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
<…>
Please, see the implementation of the JUnitPlatformProvider.setupJunitLogger() method: maven-surefire/JUnitPlatformProvider.java at surefire-3.0.0-M7 · apache/maven-surefire:
private static void setupJunitLogger()
{
Logger logger = Logger.getLogger( "org.junit" );
if ( logger.getLevel() == null )
{
logger.setLevel( WARNING );
}
}
Please, note the condition:
logger.getLevel() == null
Please, see the documentation of the Logger.getLevel() method:
public Level getLevel()
Get the log Level that has been specified for this Logger. The result may be null, which means that this logger's effective level will be inherited from its parent.
Returns:
this Logger's level
Please, note the statement:
The result may be null, which means that this logger's effective level will be inherited from its parent.
Analysis summary
This is (see the «Analysis» subsection) why:
A parent logger configuration is not taken into account by Maven Surefire Plugin.
It does not seem to be a user-friendly behavior.
Maybe, it is worth reporting it as a Maven Surefire Plugin issue.
It is necessary to introduce the explicit logger configuration for the org.junit package.
Solution
It is necessary to introduce the explicit logger configuration for the org.junit package:
org.junit.level=CONFIG
Follow-up: Checking provided complete pom.xml file
I have used the provided complete pom.xml file with the following preconditions.
I had used the same preconditions to test the solution.
Preconditions
Added test classes
Added 3 test classes annotated with #TestMethodOrder(MethodOrderer.Random.class) like this one:
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
#TestMethodOrder(MethodOrderer.Random.class)
public class Application1Test {
#Test
public void shouldAnswerWithTrue() {
Assertions.assertTrue(true);
}
#Test
public void shouldAnswerWithTrue2() {
Assertions.assertTrue(true);
}
}
Enabled parallel test execution
The content of the src/test/resources/junit-platform.properties file:
junit.jupiter.execution.parallel.enabled=true
junit.jupiter.execution.parallel.mode.default=concurrent
Added JUnit-related log level
The content of the src/test/resources/logging.properties:
.level=CONFIG
.handlers=java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level=CONFIG
org.junit.level=CONFIG
Output
$ ./mvnw clean test 2>&1 | grep -F 'MethodOrderer.Random'
CONFIG: MethodOrderer.Random default seed: 7225497639767
I am building a Spring Boot application with a MongoDB database and I am running into an issue when the application is deployed to the server and starts logging. I have done some digging on the internet and all the answer I am getting is that I need the following maven dependency and to do an install. I have done that and unfortunately the issue still remains.
I am currently using MongoDB version 4.4.11 and Spring-boot version 2.6.1
pom.xml
<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>
<parent>
<groupId>com.myproject</groupId>
<artifactId>backend</artifactId>
<version>3.2.0.RELEASE</version>
</parent>
<artifactId>pe</artifactId>
<packaging>war</packaging>
<name>myproject Backend Pe</name>
<dependencies>
<dependency>
<groupId>com.myproject</groupId>
<artifactId>core</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</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-properties-migrator</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<properties>
<start-class>com.myproject.mobileplatform_backend.app.Application</start-class>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>pe</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<!-- installs node modules -->
<execution>
<id>npm install</id>
<goals>
<goal>exec</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<executable>npm</executable>
<arguments>
<argument>install</argument>
</arguments>
<workingDirectory>${basedir}/src/main/frontend</workingDirectory>
</configuration>
</execution>
<!-- builds frontend -->
<execution>
<id>angular build</id>
<goals>
<goal>exec</goal>
</goals>
<phase>compile</phase>
<configuration>
<executable>ng</executable>
<arguments>
<argument>build</argument>
<argument>--prod</argument>
<argument>--deploy-url</argument>
<argument>dist/</argument>
</arguments>
<workingDirectory>${basedir}/src/main/frontend</workingDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Readout from localhost..log:
14-Jan-2022 11:41:57.058 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log Closing Spring root WebApplicationContext
14-Jan-2022 11:42:15.809 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log 1 Spring WebApplicationInitializer detected on classpath
14-Jan-2022 11:42:24.270 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log Initializing Spring embedded WebApplicationContext
14-Jan-2022 11:42:32.293 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.filterStart Exception starting filter [errorPageSecurityFilter]
java.lang.AbstractMethodError
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:285)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:112)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4590)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5233)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:630)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1842)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
14-Jan-2022 11:42:32.323 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log Closing Spring root WebApplicationContext
Errors when deploying to server:
Exception in thread "cluster-ClusterId{value='61dde73d6257ab22798db558', description='null'}-localhost:27017" java.lang.NoClassDefFoundError: ch/qos/logback/classic/spi/ThrowableProxy
at ch.qos.logback.classic.spi.LoggingEvent.<init>(LoggingEvent.java:119)
at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:419)
at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:383)
at ch.qos.logback.classic.Logger.info(Logger.java:595)
at com.mongodb.diagnostics.logging.SLF4JLogger.info(SLF4JLogger.java:76)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.logStateChange(DefaultServerMonitor.java:266)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:164)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: Illegal access: this web application instance has been stopped already. Could not load [ch.qos.logback.classic.spi.ThrowableProxy]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1301)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1158)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
... 8 more
Caused by: java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [ch.qos.logback.classic.spi.ThrowableProxy]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1311)
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1299)
... 10 more
Exception in thread "cluster-ClusterId{value='61dde7416257ab22798db559', description='null'}-localhost:27017" java.lang.NoClassDefFoundError: ch/qos/logback/classic/spi/ThrowableProxy
at ch.qos.logback.classic.spi.LoggingEvent.<init>(LoggingEvent.java:119)
at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:419)
at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:383)
at ch.qos.logback.classic.Logger.info(Logger.java:595)
at com.mongodb.diagnostics.logging.SLF4JLogger.info(SLF4JLogger.java:76)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.logStateChange(DefaultServerMonitor.java:266)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:164)
at java.lang.Thread.run(Thread.java:745)
Exception in thread "cluster-ClusterId{value='61dde7416257ab22798db55a', description='null'}-localhost:27017" java.lang.NoClassDefFoundError: ch/qos/logback/classic/spi/ThrowableProxy
at ch.qos.logback.classic.spi.LoggingEvent.<init>(LoggingEvent.java:119)
at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:419)
at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:383)
at ch.qos.logback.classic.Logger.info(Logger.java:595)
at com.mongodb.diagnostics.logging.SLF4JLogger.info(SLF4JLogger.java:76)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.logStateChange(DefaultServerMonitor.java:266)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:164)
at java.lang.Thread.run(Thread.java:745)
Second Error:
Exception in thread "cluster-ClusterId{value='61e1a55b4e705712d5c92121', description='null'}-localhost:27017" java.lang.NoClassDefFoundError: com/mongodb/internal/connection/DecimalFormatHelper
at com.mongodb.connection.ServerDescription.getRoundTripFormattedInMilliseconds(ServerDescription.java:1041)
at com.mongodb.connection.ServerDescription.getShortDescription(ServerDescription.java:1016)
at com.mongodb.connection.ClusterDescription.getShortDescription(ClusterDescription.java:327)
at com.mongodb.internal.connection.BaseCluster.updateDescription(BaseCluster.java:245)
at com.mongodb.internal.connection.SingleServerCluster.publishDescription(SingleServerCluster.java:125)
at com.mongodb.internal.connection.SingleServerCluster.publishDescription(SingleServerCluster.java:116)
at com.mongodb.internal.connection.SingleServerCluster.access$200(SingleServerCluster.java:41)
at com.mongodb.internal.connection.SingleServerCluster$DefaultServerDescriptionChangedListener.serverDescriptionChanged(SingleServerCluster.java:107)
at com.mongodb.internal.connection.DefaultSdamServerDescriptionManager.updateDescription(DefaultSdamServerDescriptionManager.java:127)
at com.mongodb.internal.connection.DefaultSdamServerDescriptionManager.update(DefaultSdamServerDescriptionManager.java:81)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:165)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: Illegal access: this web application instance has been stopped already. Could not load [com.mongodb.internal.connection.DecimalFormatHelper]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1301)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1158)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
... 12 more
Caused by: java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [com.mongodb.internal.connection.DecimalFormatHelper]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1311)
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1299)
... 14 more
Exception in thread "cluster-ClusterId{value='61e1a55c4e705712d5c92122', description='null'}-localhost:27017" java.lang.NoClassDefFoundError: com/mongodb/internal/connection/DecimalFormatHelper
at com.mongodb.connection.ServerDescription.getRoundTripFormattedInMilliseconds(ServerDescription.java:1041)
at com.mongodb.connection.ServerDescription.getShortDescription(ServerDescription.java:1016)
at com.mongodb.connection.ClusterDescription.getShortDescription(ClusterDescription.java:327)
at com.mongodb.internal.connection.BaseCluster.updateDescription(BaseCluster.java:245)
at com.mongodb.internal.connection.SingleServerCluster.publishDescription(SingleServerCluster.java:125)
at com.mongodb.internal.connection.SingleServerCluster.publishDescription(SingleServerCluster.java:116)
at com.mongodb.internal.connection.SingleServerCluster.access$200(SingleServerCluster.java:41)
at com.mongodb.internal.connection.SingleServerCluster$DefaultServerDescriptionChangedListener.serverDescriptionChanged(SingleServerCluster.java:107)
at com.mongodb.internal.connection.DefaultSdamServerDescriptionManager.updateDescription(DefaultSdamServerDescriptionManager.java:127)
at com.mongodb.internal.connection.DefaultSdamServerDescriptionManager.update(DefaultSdamServerDescriptionManager.java:81)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:165)
at java.lang.Thread.run(Thread.java:745)
Exception in thread "cluster-ClusterId{value='61e1a5544e705712d5c92120', description='null'}-localhost:27017" java.lang.NoClassDefFoundError: com/mongodb/internal/connection/DecimalFormatHelper
at com.mongodb.connection.ServerDescription.getRoundTripFormattedInMilliseconds(ServerDescription.java:1041)
at com.mongodb.connection.ServerDescription.getShortDescription(ServerDescription.java:1016)
at com.mongodb.connection.ClusterDescription.getShortDescription(ClusterDescription.java:327)
at com.mongodb.internal.connection.BaseCluster.updateDescription(BaseCluster.java:245)
at com.mongodb.internal.connection.SingleServerCluster.publishDescription(SingleServerCluster.java:125)
at com.mongodb.internal.connection.SingleServerCluster.publishDescription(SingleServerCluster.java:116)
at com.mongodb.internal.connection.SingleServerCluster.access$200(SingleServerCluster.java:41)
at com.mongodb.internal.connection.SingleServerCluster$DefaultServerDescriptionChangedListener.serverDescriptionChanged(SingleServerCluster.java:107)
at com.mongodb.internal.connection.DefaultSdamServerDescriptionManager.updateDescription(DefaultSdamServerDescriptionManager.java:127)
at com.mongodb.internal.connection.DefaultSdamServerDescriptionManager.update(DefaultSdamServerDescriptionManager.java:81)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:165)
at java.lang.Thread.run(Thread.java:745)
I think the main issue you are facing is related to the error presented in localhost.log:
14-Jan-2022 11:42:32.293 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.filterStart Exception starting filter [errorPageSecurityFilter]
java.lang.AbstractMethodError
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:285)
The error has to do with the inability of Tomcat to successfully initialize ErrorPageSecurityFilter.
This filter tries to prevent unauthorized access to the application error page.
It was introduced in Spring Boot 2.6.0.
The filter was initially meant as a Servlet 4.0 HttpFilter.
As you can see in the history of changes of the component, that fact had been the cause of different changes in order to provide support for containers in which the Servlet 4.0 version is not supported.
These changes has been documented in different issues, mainly this, although there are other related ones 1 2 3.
Basically, as you can check in the aforementioned history of the component, they first refactored the filter to implement Filter instead of extending HttpFilter.
In the Servlet 4 version the Filter interface provides default methods implementation for both init and destroy. To mimic this behavior and make it Servlet 3.x compatible, in a later change, the Spring developers provided a no-op implementation of init in the ErrorPageSecurityFilter itself.
As you can see in the change log, this last issue was fixed in Spring Boot 2.6.2.
On application startup, Tomcat finds and tries initializing the ErrorPageSecurityFilter filter but probably you are using a version of Tomcat still not Servlet 4 version compliant and, according to the version of Spring Boot you are using, 2.6.1, this filter provides no init implementation, and that is the reason why Tomcat complains about the AbstractMethodError.
In order to solve the problem, please, consider update your application dependencies to Spring Boot 2.6.2.
I think once updated, the different deployment related errors will go away, they seem to be caused by threading or class loading issues when Tomcat terminates abruptly the application as a consequence of the ErrorPageSecurityFilter related error.
This may be because of incompatible version of spring-data and db-driver dependency. Please check if the version of db-driver is compatible with the provided spring-data dependency.
Try this version:
SpringBoot 2.5.6 for MongoDB 4.4.11
If SpringBoot 2.6.1 if required try:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
for mongo dependency.
It seems this issue:
https://gitmetadata.com/repo/spring-projects/spring-boot/issues/29135
You might force the use of tomcat 9 with the following property in your pom:
<properties>
<tomcat.version>9.0.55</tomcat.version>
<properties>
though tomcat embedded version for spring-boot 2.6.1 should be 9.0.55
I am having trouble getting the jooq codegen tool to run with my custom JooqCodegenStrategy class. I downloaded jooq 3.12.0 and unzipped it into a directory on my Ubuntu system. In this directory, I have the following files.
jooq-3.12.0.jar
jooq-checker-3.12.0.jar
jooq-codegen-3.12.0.jar
jooq-codegen-maven-3.12.0.jar
JooqCodegenStrategy.class
JooqCodegenStrategy.java
jooq-meta-3.12.0.jar
jooq-meta-extensions-3.12.0.jar
jooq-scala_2.12-3.12.0.jar
jooq_sd3.jar
jooq.xml
mysql-connector-java-5.1.47-bin.jar*
reactive-streams-1.0.3.jar
I can successfully run the code generation tool when I do not have the following (below) in my jooq.xml.
<generator>
<strategy>
<name>com.simpletest.JooqCodegenStrategy</name>
</strategy>
</generator>
In order to build the JooqCodegenStrategy class, from terminal, I compile this Java file using:
javac -classpath jooq-meta-3.12.0.jar:jooq-codegen-3.12.0.jar JooqCodegenStrategy.java
That appears to work and it creates the JooqCodegenStrategy.class file. I package that file into a jar so I can reference it on the classpath when running the codegen tool. I create the jar file using:
jar -cvf jooq_sd3.jar JooqCodegenStrategy.class
At this point, I believe I have what I need to run the codegen tool. I run the codegen tool using this:
java -classpath jooq-3.12.0.jar:jooq-meta-3.12.0.jar:jooq-codegen-3.12.0.jar:mysql-connector-java-5.1.47-bin.jar:reactive-streams-1.0.3.jar:jooq_sd3.jar:. org.jooq.codegen.GenerationTool /jooq.xml
The error I get looks like this:
Aug 30, 2019 4:44:12 PM org.jooq.tools.JooqLogger info
INFO: Initialising properties : /jooq.xml
Aug 30, 2019 4:44:13 PM org.jooq.tools.JooqLogger error
SEVERE: Cannot read /jooq.xml. Error : com.simpletest.JooqCodegenStrategy
java.lang.ClassNotFoundException: com.simpletest.JooqCodegenStrategy
at java.net.URLClassLoader.findClass(URLClassLoader.java:382
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.jooq.codegen.GenerationTool.loadClass0(GenerationTool.java:925)
at org.jooq.codegen.GenerationTool.loadClass(GenerationTool.java:869)
at org.jooq.codegen.GenerationTool.run0(GenerationTool.java:380)
at org.jooq.codegen.GenerationTool.run(GenerationTool.java:221)
at org.jooq.codegen.GenerationTool.generate(GenerationTool.java:216)
at org.jooq.codegen.GenerationTool.main(GenerationTool.java:188)
My jooq.xml file looks like this.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration>
<jdbc>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost:3306/sd3?useSSL=false</url>
<user>myuser</user>
<password>mypass</password>
</jdbc>
<generator>
<name>org.jooq.codegen.JavaGenerator</name>
<strategy>
<name>com.simpletest.JooqCodegenStrategy</name>
</strategy>
<database>
<name>org.jooq.meta.mysql.MySQLDatabase</name>
<inputSchema>sd3</inputSchema>
<includes>.*</includes>
<excludes>sometableshere</excludes>
<forcedTypes>
<forcedType>
<name>JsonElement</name>
<expression>board_data</expression>
<types>JSON</types>
</forcedType>
</forcedTypes>
</database>
<target>
<packageName>model.data</packageName>
<directory>./src/main/java/com/simpletest/domain/</directory>
</target>
<generate>
<relations>true</relations>
<deprecated>true</deprecated>
<instanceFields>true</instanceFields>
<generatedAnnotation>true</generatedAnnotation>
<records>true</records>
<pojos>true</pojos>
<immutablePojos>false</immutablePojos>
<interfaces>false</interfaces>
<daos>true</daos>
<jpaAnnotations>true</jpaAnnotations>
<validationAnnotations>false</validationAnnotations>
<springAnnotations>true</springAnnotations>
<globalObjectReferences>true</globalObjectReferences>
<fluentSetters>true</fluentSetters>
</generate>
</generator>
</configuration>
Any ideas what I am doing wrong?
Thanks for the help.
If compiling your Java class in the local directory works, that means that your class doesn't have a package (i.e. it is in the default package). Which means your qualification of that class is wrong:
<generator>
<strategy>
<name>com.simpletest.JooqCodegenStrategy</name>
</strategy>
</generator>
It is not in the com.simpletest package. The use of the default package is generally discouraged in Java. In many cases (e.g. in this one too, I think), you will not be able to load the class from a random position.
Better add the package declaration to your class:
package com.simpletest;
And move the class in a com/simpletest subdirectory.
I have osgi (felix) javafx application. When launch application I get:
May 30, 2015 10:44:59 PM com.sun.javafx.css.StyleManager loadStylesheetUnPrivileged
WARNING: Resource "com/sun/javafx/scene/control/skin/modena/modena.css" not found.
May 30, 2015 10:44:59 PM com.sun.javafx.css.StyleManager loadStylesheetUnPrivileged
WARNING: Resource "com/sun/javafx/scene/control/skin/modena/modena.css" not found.
And my stages are without css rules (nor borders etc). The only solution I found is
Bundle systemBundle =FrameworkUtil.getBundle(MyApplication.class).getBundleContext().getBundle(0);
URL url0=systemBundle.getResource("com/sun/javafx/scene/control/skin/modena/modena.css");
URL url1=systemBundle.getResource("com/sun/javafx/scene/control/skin/modena/modena-no-transparency.css");
scene.getStylesheets().add(url0.toString());
scene.getStylesheets().add(url1.toString());
However it's bad solution and besides I need to do it for every stage. What is a better solution to solve this problem?
I found the answer. Is was necessary to add packages to import section of manifest.mf. As I use maven it could be done via maven-bundle-plugin
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Import-Package>com.sun.javafx.scene.control.skin.modena,*</Import-Package>
</instructions>
</configuration>
</plugin>
The most important is the asterisk sign at the end. It is necessary in order to add all auto detected packages this bundle needs. If we omit this sign then we will have to add all packages manually.
I'm writing a server that embeds Jetty w/ Jersey. When I execute from Eclipse, everything is great. However, if I assemble my server and all dependencies into a single jar using Maven's assembly:single goal, I get an exception:
Sep 26, 2012 5:35:59 PM com.sun.jersey.spi.container.ContainerResponse write
SEVERE: A message body writer for Java class com.acme.server.webservice.
exception.WebServiceFailure, and Java type class com.acme.server.webserv
ice.exception.WebServiceFailure, and MIME media type application/json was not fo
und
Sep 26, 2012 5:35:59 PM com.sun.jersey.spi.container.ContainerResponse write
SEVERE: The registered message body writers compatible with the MIME media type
are:
*/* ->
com.sun.jersey.server.impl.template.ViewableMessageBodyWriter
17:35:59.372 [qtp184245201-22 - /] ERROR o.a.h.ReflectorServletProcessor - onReq
uest()
javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A mess
age body writer for Java class com.acme.server.webservice.exception.WebS
erviceFailure, and Java type class com.acme.server.webservice.exception.
WebServiceFailure, and MIME media type application/json was not found
at com.sun.jersey.spi.container.ContainerResponse.write(ContainerRespons
e.java:285) ~[vma-server-0.0.1-SNAPSHOT-jar-with-dependencies.jar:na]
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequ
est(WebApplicationImpl.java:1457) ~[server-0.0.1-SNAPSHOT-jar-with-dependenc
ies.jar:na]
...
The full trace is here, if it's useful:
https://gist.github.com/3790817
Maven throws no errors while creating the jar-with-dependencies.
I'm a novice with Maven and deployment of Java, and I'm really not sure how to proceed with debugging.
Also, while I need to solve this issue I'd also appreciate any suggested work-arounds as I need to produce an executable demo of my server ASAP that a Pointy-Haired Boss (tm) can execute without Eclipse.
Solution:
Based on Pavel's answer, I dropped the maven-assemly-plugin in favor of maven-shade-plugin. Here's the shade configuration that worked for me:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<!-- use transformer to handle merge of META-INF/services - see http://java.net/jira/browse/JERSEY-440?focusedCommentId=14822&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#action_14822 -->
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
</transformers>
<filters>
<!-- filter to address "Invalid signature file" issue - see http://stackoverflow.com/a/6743609/589215-->
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
You are not merging Jersey jars correctly.
Jersey 1.x uses META-INF/services mechanism to discover its components and assembly:single probably just copies everything into single jar, overriding already present files BUT META-INF/services file(s) needs to be CONCATENATED.
Try using jersey-bundle (com.sun.jersey:jersey-bundle:1.14) or fix your assembly settings (or find another plugin to do it better).
Could you post your pom ?
Do you mark some dependencies as provided ?
It's something quite different to build a standalone app and a webapp, as some jars a supposed to be provided by the web container (tomcat or other).
As your container is "embedded" in your app (and not your app in the container) then maybe you don't manage correctly these dependencies.