2016-07-04 81 views
1

當前我正在處理我公司的一個項目,該項目將XML數據導入到我們的數據庫。在這樣做的過程中,我依賴於已經創建並在其他項目中使用的一些基本配置項目,即EntityManagerBuilder或其他用於創建與我們的oracle數據庫的連接的實用程序類。而在我看來,這些依賴關係正在給我造成一些問題。Maven安裝成功,但jar無法從bash(CLI)正常工作

如果我在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> 

回答

0

我認爲這可能是事做在你的Maven的依賴關係管理,因爲你還沒有自動指定的版本和Maven數字出那些版本。

但是,當您運行該應用程序時,您需要將這些罐子放入您的類路徑中,否則可能會因爲罐子不可用而最終得到ClassNotFoundException。所以除非你知道你的依賴關係是否像你提到的那樣,並將它們添加到你的類路徑中,否則你最終會看到錯誤。

在您的應用程序中啓用進一步的日誌級別可能會值得您指出錯誤的位置。您還可以嘗試查看在失敗點是否引用了外部庫,這是您的類路徑中不可用的庫。

您是否也請分享您如何通過CLI運行您的應用程序。

+0

我認爲你對依賴管理是正確的。我現在正在研究它,看起來另一個jar在那裏,但它的一個SNAPSHOT版本,這不知怎的搞砸了。我正在用'java -jar foo-import.jar/data -o option'運行它。謝謝你指點我正確的方向。 – kaba713

相關問題