class 未发现 Google Guice 异常
class not found exception with Google Guice
我正在尝试使用 Java 和 Google Guice 启动我的第一个应用程序。最好是我能在网上找到其他无法解决我的问题的地方。当我从控制台 运行 我的 java 应用程序时,我收到以下错误:
matt@linux ~/dev/options/console/target $ java -jar ServerConsole-R1.jar
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/inject/Module
at Application.Startup.main(Startup.java:38)
Caused by: java.lang.ClassNotFoundException: com.google.inject.Module
我的 pom 文件中引用了 google guice。当我调用 mvn -compile 或 mvn -install 时,Maven 没有给出任何错误。我检查了本地maven respository目录,它已经下载了guice jar文件。
我的 pom 文件如下所示:
<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>tatmancapital</groupId>
<artifactId>ServerConsole</artifactId>
<version>R1</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.google.inject/guice -->
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-multibindings</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>Application.Startup</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
我破解了 jar 文件并将其与 spring 引导项目 jar 文件进行了比较,我在 jar 文件中发现了一个丢失的文件夹:BOOT-INF。
看来我的所有参考文献都是正确的。但是构建输出缺少支持的 jar 文件。
缺少什么?
谢谢
马特
我最终使用了不同的包。
我的新 pom 文件如下所示(我还删除了上面显示的未使用的依赖项,但该更改没有解决我的问题):
<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>tatmancapital</groupId>
<artifactId>ServerConsole</artifactId>
<version>R1</version>
<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<archive>
<manifest>
<mainClass>Application.Startup</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>
</project>
这给了我一个可执行的 JAR 文件。谢谢@nullpointer。
jar 文件名太可怕了。使用清单的包名称成员没有影响它。
男
在 target/ 中有了这个 pom,你必须有两个不同的 jar,ServerConsole-R1.jar 和 ServerConsole-R1-jar-with-dependencies.jar,尝试执行第二个
第一个小 jar 可以通过 'mvn java:exec' 执行,添加所有必要的类路径
我正在尝试使用 Java 和 Google Guice 启动我的第一个应用程序。最好是我能在网上找到其他无法解决我的问题的地方。当我从控制台 运行 我的 java 应用程序时,我收到以下错误:
matt@linux ~/dev/options/console/target $ java -jar ServerConsole-R1.jar
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/inject/Module
at Application.Startup.main(Startup.java:38)
Caused by: java.lang.ClassNotFoundException: com.google.inject.Module
我的 pom 文件中引用了 google guice。当我调用 mvn -compile 或 mvn -install 时,Maven 没有给出任何错误。我检查了本地maven respository目录,它已经下载了guice jar文件。
我的 pom 文件如下所示:
<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>tatmancapital</groupId>
<artifactId>ServerConsole</artifactId>
<version>R1</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.google.inject/guice -->
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-multibindings</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>Application.Startup</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
我破解了 jar 文件并将其与 spring 引导项目 jar 文件进行了比较,我在 jar 文件中发现了一个丢失的文件夹:BOOT-INF。
看来我的所有参考文献都是正确的。但是构建输出缺少支持的 jar 文件。
缺少什么?
谢谢 马特
我最终使用了不同的包。
我的新 pom 文件如下所示(我还删除了上面显示的未使用的依赖项,但该更改没有解决我的问题):
<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>tatmancapital</groupId>
<artifactId>ServerConsole</artifactId>
<version>R1</version>
<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<archive>
<manifest>
<mainClass>Application.Startup</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>
</project>
这给了我一个可执行的 JAR 文件。谢谢@nullpointer。
jar 文件名太可怕了。使用清单的包名称成员没有影响它。
男
在 target/ 中有了这个 pom,你必须有两个不同的 jar,ServerConsole-R1.jar 和 ServerConsole-R1-jar-with-dependencies.jar,尝试执行第二个
第一个小 jar 可以通过 'mvn java:exec' 执行,添加所有必要的类路径