Maven安装成功,但jar无法从bash(CLI)正常工作

时间:2016-07-04 14:06:09

标签: java eclipse bash maven

目前我正在为我公司的一个项目工作,该项目将XML数据导入我们的数据库。在执行此操作时,我依赖于已在其他项目中创建和使用的一些基本配置项目,即EntityManagerBuilder或其他用于创建与oracle数据库的连接的实用程序类。在我看来,这些依赖关系正在为我创造一些问题。

如果我在eclipse中启动它,我的项目运行得很好。当我使用mvn clean install -DskipTests创建项目时,它构建得很好。 但是,当我想从命令行运行它时,应用程序启动,并在几行代码停止后,不会抛出任何错误或异常。

我认为它与某些依赖项有关的原因是通过日志记录我设法找到应用程序停止的点。由于它停在我可以调查的一点,我就是这么做的。我下载了源代码,只添加了一些日志记录,突然我的应用程序在该类中没有任何问题,而是在下一次静态调用其他类时停止了。

我根本不知道在哪里搜索错误。由于这是一个必须由它自己作为月度任务运行的应用程序,因此不能从eclipse执行它。

希望有人可以给我一个提示如何解决这个问题。

这是我的POM:

<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>
<parent>
    <groupId>com.company.infrastructure.foo</groupId>
    <artifactId>foo</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>foo-import</artifactId>
<packaging>jar</packaging>
<name>FooImport</name>

<properties>
    <company.consoleapp.main.class>com.company.infrastructure.foo.import.FooImporter</company.consoleapp.main.class>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.company.maven</groupId>
            <artifactId>company-standalone-dm</artifactId>
            <version>${company.parent.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>

    <!-- Logging -->

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
    </dependency>

    <!-- Utilities -->

    <dependency>
        <groupId>args4j</groupId>
        <artifactId>args4j</artifactId>
    </dependency>

    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.2.11</version>
    </dependency>   

    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-core</artifactId>
        <version>2.2.11</version>
    </dependency>

    <!-- Using foo-dataaccess -->

    <dependency>
        <groupId>com.company.infrastructure.marken</groupId>
        <artifactId>foo-dataaccess</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <scope>compile</scope>
    </dependency>

</dependencies>

<build>
    <finalName>foo-import</finalName>
    <plugins>

        <!-- Consoleapp-Mixin -->

        <plugin>
            <groupId>com.github.odavid.maven.plugins</groupId>
            <artifactId>mixin-maven-plugin</artifactId>
            <configuration>
                <mixins>
                    <mixin>
                        <groupId>com.company.maven</groupId>
                        <artifactId>company-consoleapp-mixin</artifactId>
                        <version>${company.parent.version}</version>
                    </mixin>
                </mixins>
            </configuration>
        </plugin>

    </plugins>

</build>

1 个答案:

答案 0 :(得分:0)

我认为这可能与您在maven中的依赖关系管理有关,因为您没有指定版本和maven自动计算出这些版本。

但是,当您运行应用程序时,您需要将这些jar放在类路径中,否则您最终可能会得到ClassNotFoundException,因为jar不可用。因此,除非你弄清楚你提到的依赖项是什么,并将它们添加到类路径中,否则最终会看到错误。

可能值得在应用程序中启用更高级别的日志记录,以便为您提供错误位置的指示。您还可以尝试查看在故障点是否引用了外部库,这是您的类路径中不可用的库。

您是否还可以通过CLI分享您运行应用程序的方式。

相关问题