我尝试从mac终端运行一个简单的maven项目。
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>HelloWorld</artifactId>
<version>1.0</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<!-- here we specify that we want to use the main method within the Controller class -->
<mainClass>com.helloworld.Countries</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
</project>
我做过专业 Package ,当我试着跑时候:
java -jar target/HelloWorld-1.0.jar
...我收到此错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/simple/JSONValue
java.lang.NoClassDefFoundError
只在MacOS上运行吗?我在Windows上做了同样的项目,它运行得很好。
有没有办法让它独立于操作系统?
1条答案
按热度按时间ehxuflar1#
解决方案是使用Maven阴影插件。这是我最后的POM。