java - OCommandExecutorNotFoundException 通过 jar 文件创建 OrientDB 数据库

标签 java linux eclipse maven orientdb

我们想在 Linux 系统上导入数据。所以我们有 2 个 Java 文件用于导入。一个 (OrientDBMain.java) 用于创建一个执行所有工作的对象。另一个(OrientDB.java)包含所有数据库功能,如设置索引等。第二个文件以:

public class OrientDB {
    private OrientGraphFactory factoryGraph;
    private ODatabaseDocumentTx db;
    private String csvPath;

    @SuppressWarnings("resource")
    public OrientDB(String dbPath) {
        OGlobalConfiguration.STORAGE_KEEP_OPEN.setValue(true);
        OGlobalConfiguration.ENVIRONMENT_CONCURRENT.setValue(false);
        db = new ODatabaseDocumentTx(dbPath).create();
    }
...

WindowsMAC 上的 Eclipse 中运行此程序很好。没有错误,数据已正确导入。

但现在我们想在我们的 Linux 系统上运行它。因此,我们设置了一个 Maven 项目 (m2e) 并在此处导出了一个包含所有依赖项的 Jar 文件:

<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>mapegy</groupId>
  <artifactId>orientdbcsv</artifactId>
  <version>0.0.2-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>orientdbcsv</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.orientechnologies</groupId>
        <artifactId>orientdb-graphdb</artifactId>
        <version>2.0-M1</version>
    </dependency>
  </dependencies>
  <build>
  <plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
  <configuration>
    <archive>
      <manifest>
            <mainClass>mapegy.orientdbcsv.OrientDBMain</mainClass>
          </manifest>
    </archive>
    <descriptorRefs>
    <descriptorRef>jar-with-dependencies</descriptorRef>
    </descriptorRefs>
  </configuration>
  <executions>
    <execution>
      <id>make-assembly</id>
    <phase>package</phase>
      <goals>
        <goal>single</goal>
      </goals>
    </execution>
  </executions>
</plugin>
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>2.3.2</version>
  <configuration>
  <source>${jdk.version}</source>
  <target>${jdk.version}</target>
  </configuration>
  </plugin>
</plugins>
  </build>
</project>

但是如果我们现在运行那个 Jar,我们会收到一些错误。他们说抛出了一些 OCommandExecutorNotFoundException。但是如果它直接在 Eclipse 中运行良好,那又如何呢?我们有 2 个参数 {pathtoimportdata, pathtodestinationdb}。

C:\eclipse-workspace\orientdbcsv\target>java -jar orientdbcsv-0.0.2-SNAPSHOT-jar
-with-dependencies.jar "C:\data" "C:\orientdb-community-2.0-M1\databases\test"
Exception in thread "main" com.orientechnologies.orient.core.exception.ODatabase
Exception: Cannot create database
        at com.orientechnologies.orient.core.db.record.ODatabaseRecordAbstract.c
reate(ODatabaseRecordAbstract.java:289)
        at com.orientechnologies.orient.core.db.ODatabaseWrapperAbstract.create(
ODatabaseWrapperAbstract.java:61)
        at com.orientechnologies.orient.core.db.ODatabaseRecordWrapperAbstract.c
reate(ODatabaseRecordWrapperAbstract.java:72)
        at com.orientechnologies.orient.core.db.ODatabaseWrapperAbstract.create(
ODatabaseWrapperAbstract.java:56)
        at com.orientechnologies.orient.core.db.ODatabaseRecordWrapperAbstract.c
reate(ODatabaseRecordWrapperAbstract.java:66)
        at mapegy.orientdbcsv.OrientDB.<init>(OrientDB.java:36)
        at mapegy.orientdbcsv.OrientDBMain.main(OrientDBMain.java:6)
Caused by: com.orientechnologies.orient.core.command.OCommandExecutorNotFoundExc
eption: Cannot find a command executor for the command request: sql.select count
(*) from ORole where name.type() not in ["STRING"] and name is not null
        at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.par
se(OCommandExecutorSQLDelegate.java:48)
        at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.par
se(OCommandExecutorSQLDelegate.java:33)
        at com.orientechnologies.orient.core.storage.OStorageEmbedded.command(OS
torageEmbedded.java:69)
        at com.orientechnologies.orient.core.command.OCommandRequestTextAbstract
.execute(OCommandRequestTextAbstract.java:59)
        at com.orientechnologies.orient.core.metadata.schema.OClassImpl.checkPer
sistentPropertyType(OClassImpl.java:1597)
        at com.orientechnologies.orient.core.metadata.schema.OClassImpl.addPrope
rty(OClassImpl.java:1911)
        at com.orientechnologies.orient.core.metadata.schema.OClassImpl.createPr
operty(OClassImpl.java:580)
        at com.orientechnologies.orient.core.metadata.security.OSecurityShared.c
reateMetadata(OSecurityShared.java:350)
        at com.orientechnologies.orient.core.metadata.security.OSecurityShared.c
reate(OSecurityShared.java:282)
        at com.orientechnologies.orient.core.metadata.security.OSecurityProxy.cr
eate(OSecurityProxy.java:70)
        at com.orientechnologies.orient.core.metadata.OMetadataDefault.create(OM
etadataDefault.java:84)
        at com.orientechnologies.orient.core.db.record.ODatabaseRecordAbstract.c
reate(ODatabaseRecordAbstract.java:269)
        ... 6 more

那么问题来了。为什么它会抛出该错误以及为什么它在 Eclipse 中可以正常工作。也许您知道其他方法可以轻松轻松地为 OrientDB 编译导入脚本。

谢谢。

最佳答案

这是因为一些文件在不同的 jar 中重复,所以一些配置丢失了。

这些文件是: META-INF/services/com.orientechnologies.orient.core.sql.functions.OSQLFunctionFactory META-INF/services/com.orientechnologies.orient.core.sql.OCommandExecutorSQLFactory

使用 shade 插件尝试下一个 pom,并尝试使用生成的 shaded-jar.jar:

            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <finalName>shaded-jar</finalName>
                <transformers>
                    <transformer
                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                        <resource>META-INF/services/com.orientechnologies.orient.core.sql.functions.OSQLFunctionFactory</resource>
                    </transformer>
                    <transformer
                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                        <resource>META-INF/services/com.orientechnologies.orient.core.sql.OCommandExecutorSQLFactory</resource>
                    </transformer>
                    <transformer   implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <mainClass>mapegy.orientdbcsv.OrientDBMain</mainClass>
                    </transformer>
                </transformers>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

关于java - OCommandExecutorNotFoundException 通过 jar 文件创建 OrientDB 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26490352/

相关文章:

eclipse - 新的 MapReduce 架构和 Eclipse

java - 更改未在 Eclipse 中更新

java - jCuda 指针函数中的索引

java - java程序中的权限被拒绝问题

java - Java 中的抽象对象比较

linux - 如何为物联网设备(基于 Linux)进行软件部署?

java - 如何做条件Gson反序列化默认值

linux - 在 shell 脚本中,如何在执行到标准输出(不是标准错误)时回显 shell 命令?

linux - 如何在 Linux 上使用 sudo 在后台运行 dotnet 应用程序?

java - Eclipse 断点蓝色圆圈与玻璃图标?