用IntelliJ制作OrientDB可执行jar

时间:2016-04-13 15:59:28

标签: java maven intellij-idea jar orientdb

我使用Maven为ide intellij创建了一个java应用程序,包括几个依赖项(特别是OrientDb和Bouncy Castle)。

应用程序与ide正常工作,但我需要使用ssh在另一台计算机上运行它。 所以使用Maven Assembly Plugin(http://maven.apache.org/plugins/maven-assembly-plugin/usage.html)我制作了一个可执行jar。 但是当我运行它时,我得到了这个错误:

$ java -jar 1-1.0-SNAPSHOT-jar-with-dependencies.jar 
apr 13, 2016 5:55:28 PM com.orientechnologies.common.log.OLogManager log
INFORMAZIONI: OrientDB auto-config DISKCACHE=4.075MB (heap=1.751MB os=7.874MB disk=39.975MB)
Exception in thread "main" com.orientechnologies.common.exception.OException: Error on creation of shared resource
    at com.orientechnologies.common.concur.resource.OSharedContainerImpl.getResource(OSharedContainerImpl.java:66)
    at com.orientechnologies.orient.core.storage.OStorageAbstract.getResource(OStorageAbstract.java:143)
    at com.orientechnologies.orient.core.metadata.OMetadataDefault.init(OMetadataDefault.java:196)
    at com.orientechnologies.orient.core.metadata.OMetadataDefault.load(OMetadataDefault.java:76)
    at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.initAtFirstOpen(ODatabaseDocumentTx.java:2901)
    at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.open(ODatabaseDocumentTx.java:259)
    at bcvis.Main.main(Main.java:26)
Caused by: com.orientechnologies.orient.core.command.OCommandExecutorNotFoundException: Cannot find a command executor for the command request: sql.select from OFunction order by name
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.parse(OCommandExecutorSQLDelegate.java:72)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.parse(OCommandExecutorSQLDelegate.java:42)
    at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.command(OAbstractPaginatedStorage.java:1400)
    at com.orientechnologies.orient.core.sql.query.OSQLQuery.run(OSQLQuery.java:72)
    at com.orientechnologies.orient.core.sql.query.OSQLSynchQuery.run(OSQLSynchQuery.java:85)
    at com.orientechnologies.orient.core.query.OQueryAbstract.execute(OQueryAbstract.java:33)
    at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.query(ODatabaseDocumentTx.java:714)
    at com.orientechnologies.orient.core.metadata.function.OFunctionLibraryImpl.load(OFunctionLibraryImpl.java:65)
    at com.orientechnologies.orient.core.metadata.OMetadataDefault$4.call(OMetadataDefault.java:201)
    at com.orientechnologies.orient.core.metadata.OMetadataDefault$4.call(OMetadataDefault.java:197)
    at com.orientechnologies.common.concur.resource.OSharedContainerImpl.getResource(OSharedContainerImpl.java:64)
    ... 6 more

我该怎么做才能解决这个问题?我也对其他构建解决方案持开放态度,但我对Java / Maven不是很有经验。

这是我的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>1</groupId>
    <artifactId>1</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>com.orientechnologies</groupId>
            <artifactId>orientdb-graphdb</artifactId>
            <version>2.1.15</version>
        </dependency>
        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcprov-jdk16</artifactId>
            <version>1.45</version>
        </dependency>
    </dependencies>
    <build>
    <plugins>
    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.6</version>
        <configuration>
            <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
            <archive>
                <manifest>
                    <mainClass>bcvis.Main</mainClass>
                </manifest>
            </archive>
        </configuration>
        <executions>
            <execution>
                <id>make-assembly</id> <!-- this is used for inheritance merges -->
                <phase>package</phase> <!-- bind to the packaging phase -->
                <goals>
                    <goal>single</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

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

修改

喜欢@ wolf4ood建议我尝试使用maven shade插件和这个POM

<?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>1</groupId>
    <artifactId>1</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>com.orientechnologies</groupId>
            <artifactId>orientdb-graphdb</artifactId>
            <version>2.1.15</version>
        </dependency>
        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcprov-jdk16</artifactId>
            <version>1.45</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <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>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </excludes>
                                </filter>
                            </filters>

                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer"/>

                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>bcvis.Main</mainClass>
                                </transformer>


                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project> 

我把那个过滤器修复了这个错误:

Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes

但我得到的错误与以前完全相同:

$ java -jar 1-1.0-SNAPSHOT.jar 
apr 13, 2016 9:59:16 PM com.orientechnologies.common.log.OLogManager log
INFORMAZIONI: OrientDB auto-config DISKCACHE=4.075MB (heap=1.751MB os=7.874MB disk=40.019MB)
Exception in thread "main" com.orientechnologies.common.exception.OException: Error on creation of shared resource
    at com.orientechnologies.common.concur.resource.OSharedContainerImpl.getResource(OSharedContainerImpl.java:66)
    at com.orientechnologies.orient.core.storage.OStorageAbstract.getResource(OStorageAbstract.java:143)
    at com.orientechnologies.orient.core.metadata.OMetadataDefault.init(OMetadataDefault.java:196)
    at com.orientechnologies.orient.core.metadata.OMetadataDefault.load(OMetadataDefault.java:76)
    at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.initAtFirstOpen(ODatabaseDocumentTx.java:2901)
    at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.open(ODatabaseDocumentTx.java:259)
    at bcvis.Main.main(Main.java:26)
Caused by: com.orientechnologies.orient.core.command.OCommandExecutorNotFoundException: Cannot find a command executor for the command request: sql.select from OFunction order by name
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.parse(OCommandExecutorSQLDelegate.java:72)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.parse(OCommandExecutorSQLDelegate.java:42)
    at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.command(OAbstractPaginatedStorage.java:1400)
    at com.orientechnologies.orient.core.sql.query.OSQLQuery.run(OSQLQuery.java:72)
    at com.orientechnologies.orient.core.sql.query.OSQLSynchQuery.run(OSQLSynchQuery.java:85)
    at com.orientechnologies.orient.core.query.OQueryAbstract.execute(OQueryAbstract.java:33)
    at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.query(ODatabaseDocumentTx.java:714)
    at com.orientechnologies.orient.core.metadata.function.OFunctionLibraryImpl.load(OFunctionLibraryImpl.java:65)
    at com.orientechnologies.orient.core.metadata.OMetadataDefault$4.call(OMetadataDefault.java:201)
    at com.orientechnologies.orient.core.metadata.OMetadataDefault$4.call(OMetadataDefault.java:197)
    at com.orientechnologies.common.concur.resource.OSharedContainerImpl.getResource(OSharedContainerImpl.java:64)
    ... 6 more

2 个答案:

答案 0 :(得分:1)

我找到了解决问题的方法。

事实是我只需要包的orientdb-core而不是所有的orientdb-graph。将maven依赖关系更改为

<dependency>
            <groupId>com.orientechnologies</groupId>
            <artifactId>orientdb-core</artifactId>
            <version>2.1.15</version>
</dependency>

让奇怪的异常消失了!

答案 1 :(得分:0)

问题是META-INF /服务中的JAVA服务。它们未合并到您的可执行文件中。因此,某些执行程序未正确注册。您应该使用maven shade插件来构建jar并使用资源转换器

https://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html