目前我正在公司开展一个项目,该项目将 XML 数据导入到我们的数据库中。在执行此操作时,我依赖于一些已在其他项目中创建和使用的基本配置项目,即用于创建与 Oracle 数据库的连接的 EntityManagerBuilder 或其他实用程序类。在我看来,这些依赖关系给我带来了一些问题。
如果我在 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>
最佳答案
我认为这可能与您在 Maven 中的依赖管理有关,因为您没有指定版本,而 Maven 会自动计算出这些版本。
但是,当您运行应用程序时,您需要将这些 jar 放在您的类路径中,否则您可能最终会收到 ClassNotFoundException,因为这些 jar 不可用。因此,除非您弄清楚您提到的依赖项并将它们添加到您的类路径中,否则您最终会看到错误。
可能值得在您的应用程序中启用更高级别的日志记录,以便为您提供错误所在的一些指示。您还可以尝试看看在失败时是否引用了外部库,该库在您的类路径中不可用。
您能否也分享一下您如何通过 CLI 运行您的应用程序。
关于java - Maven 安装成功,但 jar 无法从 bash (CLI) 正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38186671/