gpt4 book ai didi

java - 执行具有 Maven 依赖项的 jar 文件时出错。 java.lang.NoClassDefFoundError : org/opengis/feature/type/Name

转载 作者:行者123 更新时间:2023-12-01 19:34:15 25 4
gpt4 key购买 nike

我正在将我的 java 应用程序导出到单个 JAR 文件中,但是当我尝试执行它时,我总是遇到相同的错误。

java.lang.NoClassDefFoundError:org/opengis/feature/type/Name

显然有问题,包括 opengis 依赖项。

我正在使用 shade 插件和 mvn package 命令来生成 JAR 文件。

这里我包含了我的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>

<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>org.geotools</groupId>
<artifactId>DataEngine</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>DataEngine</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<geotools.version>23-SNAPSHOT</geotools.version>
<start-class>exe.Main</start-class>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-shapefile</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-swing</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-epsg-hsql</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-geotiff</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-image</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-wms</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-graphx_2.12</artifactId>
<version>2.4.4</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-hive_2.12</artifactId>
<version>2.4.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.12</artifactId>
<version>2.4.4</version>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>3.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-service</artifactId>
<version>3.1.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.opengis</groupId>
<artifactId>geoapi</artifactId>
<version>3.0.1</version>
</dependency>

</dependencies>

<repositories>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net repository</name>
<url>http://download.java.net/maven/2</url>
</repository>
<repository>
<id>osgeo</id>
<name>Open Source Geospatial Foundation Repository</name>
<url>http://download.osgeo.org/webdav/geotools/</url>
</repository>
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>boundless</id>
<name>Boundless Maven Repository</name>
<url>http://repo.boundlessgeo.com/main</url>
</repository>
<repository>
<id>spark graphx</id>
<name>spark graphx</name>
<url>https://mvnrepository.com/artifact/org.apache.spark/spark-graphx</url>
</repository>
<repository>
<id>spark hive</id>
<name>spark hive</name>
<url>https://mvnrepository.com/artifact/org.apache.spark/spark-hive</url>
</repository>
<repository>
<id>spark sql</id>
<name>spark sql</name>
<url>https://mvnrepository.com/artifact/org.apache.spark/spark-sql</url>
</repository>
<repository>
<id>jdbc hive</id>
<name>jdbc hive</name>
<url>https://mvnrepository.com/artifact/org.apache.hive/hive-jdbc</url>
</repository>
<repository>
<id>hive service</id>
<name>hive service</name>
<url>https://mvnrepository.com/artifact/org.apache.hive/hive-service</url>
</repository>
<repository>
<id>mysql driver</id>
<name>mysql driver</name>
<url>https://mvnrepository.com/artifact/mysql/mysql-connector-java</url>
</repository>
<repository>
<id>commons-loggin</id>
<name>commons-loggin</name>
<url>https://mvnrepository.com/artifact/commons-logging/commons-logging</url>
</repository>
<repository>
<id>opengis</id>
<name>opengis</name>
<url>https://mvnrepository.com/artifact/org.opengis/geoapi</url>
</repository>
</repositories>

<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>exe.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>junit:junit</include>
<include>org.geotools:gt-shapefile</include>
<include>org.geotools:gt-swing</include>
<include>org.geotools:gt-epsg-hsql</include>
<include>org.geotools:gt-geotiff</include>
<include>org.geotools:gt-image</include>
<include>org.geotools:gt-wms</include>
<include>org.apache.spark:spark-graphx_2.12</include>
<include>org.apache.spark:spark-hive_2.12</include>
<include>org.apache.spark:spark-sql_2.12</include>
<include>org.apache.hive:hive-jdbc</include>
<include>org.apache.hive:hive-service</include>
<include>mysql:mysql-connector-java</include>
<include>commons-logging:commons-logging</include>
<include>org.opengis:geoapi</include>
</includes>
</artifactSet>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>exe.Main</mainClass>
</transformer>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</pluginManagement>
</build>
</project>

这是我得到的完整错误跟踪:

Exception in thread "main" java.lang.NoClassDefFoundError: org/opengis/feature/type/Name
at exe.Main.initialize(Main.java:119)
at exe.Main.main(Main.java:86)
Caused by: java.lang.ClassNotFoundException: org.opengis.feature.type.Name
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more

我真的很感激任何帮助/建议。我已经在这一点上堆栈了很长一段时间,但仍然没有得到任何解决方案。

最佳答案

您应该避免使用 Maven 程序集插件,因为它会导致您 issues将来。 GeoTools模块通常在其 META-INF/services 目录中定义一个或多个与其他模块中定义的文件同名的文件。程序集插件只是将具有相同名称的文件复制到彼此之上,而不是合并它们的内容。

好消息是Maven shade plugin可以使用它,它将正确合并应用程序使用的每个 GeoTools 模块中的 META-INF/services 文件。

请参阅FAQ for more details .

最后,请使用稳定版本,除非您明确为我们测试候选版本(例如 22-RC,在 22.0 版本中变得无用)。

关于java - 执行具有 Maven 依赖项的 jar 文件时出错。 java.lang.NoClassDefFoundError : org/opengis/feature/type/Name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58428411/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com