实际上,我想使用 Weld-SE 创建一个类似于 JavaSE 应用程序的小型“Hello WOrld”示例,但似乎存在运行时错误。
这是我的课:
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));
}
}
这是我的 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>
我已经安装了 Java JDK 1.8.0_151 和 Maven 3.5.2。编译过程成功,但是当我在目标目录中执行创建的 jar 文件时,我会一直收到以下错误:
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)
...
有什么我没有提到或我做错了吗?是否有任何依赖性,不包括在内?
我再次安装了 Java、Maven 和 Eclipse,但没有任何帮助。
非常感谢丹尼尔