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

时间:2014-10-21 15:21:44

标签: 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();
    }
...

Windows MAC 上的 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个args {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编译导入脚本。

谢谢。

1 个答案:

答案 0 :(得分:1)

这是因为有些文件在不同的jar中重复,因此有些配置会丢失。

文件是: META-INF /服务/ com.orientechnologies.orient.core.sql.functions.OSQLFunctionFactory META-INF /服务/ 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>