Actually i want to create a small "Hello WOrld"-like Example of a JavaSE-Application with Weld-SE, but it seems that there is a runtime error.
Here is my class:
package de.mycompany.weldapp;
import java.util.List;
import javax.enterprise.event.Observes;
import javax.inject.Singleton;
import org.jboss.weld.environment.se.bindings.Parameters;
import org.jboss.weld.environment.se.events.ContainerInitialized;
@Singleton
public class App
{
public void printHello(@Observes ContainerInitialized event, @Parameters List<String> parameters) {
System.out.println("Hello " + parameters.get(0));
}
}
An here is my 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>
<groupId>de.mycompany</groupId>
<artifactId>weldapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>weldapp</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-shaded</artifactId>
<version>3.0.2.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<mainClass>de.mycompany.weldapp.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
I have installed Java JDK 1.8.0_151 and Maven 3.5.2. The compile-process was successful, but when i execute the created jar-file in the target-directory, i will get the following error all the time:
A JNI error has occurred, plase check your installation and try again.
Exception in thread "main" java.lang.noClassDefFoundError: org/jboss/environment/se/events/ContainerInitialized
at java.lang.Class.getDeclaredMethods0(native Method)
...
Caused by : java.lang.ClassNotFoundException: org.jboss.weld.environment.se.events.ContainerInitialized
at java.net.URLCLassLoader.findClass(Unknown Source)
...
Is there anything that i did not mention or that i am doing wrong? Is there any dependency, that was not included?
I have installed Java, Maven and Eclipse again, but nothing helped.
Thanks a lot Daniel
Since you're running in SE mode, you do not want to make any dependencies provided. So remove
<scope>provided</scope>
from yourcdi-api
dependency.Edit: I reran your test, and realized what's happening for you. You're using the
maven-jar-plugin
to create your jAR. I'm assuming though you want to use the shade plugin to create an uber JAR. Here's an updatedpom.xml
you can use that seems to work (note that I also changed your main class to be the Weld start up class):