首先配置好plugins,否则报错:Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<configuration>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
运行时:
java -cp log-sdk-demo-1.0-SNAPSHOT.jar xxxx.logDemo
否则直接java -jar 会报错:Can't execute jar- file: “no main manifest attribute”
参考:
2、https://stackoverflow.com/questions/9689793/cant-execute-jar-file-no-main-manifest-attribute