我正在使用main/resources/antlr-4.2-complete.jar
外部库。我已经将它包含在我的类路径中。但是当我运行测试目标时,在 Eclipse 中我收到以下消息
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.048 sec <<< FAILURE!
checkGrammar(br.com.stoneage.GrammarTest) Time elapsed: 0.011 sec <<< ERROR!
java.lang.NoClassDefFoundError: org/antlr/v4/runtime/CharStream
Run Code Online (Sandbox Code Playgroud)
所以我知道测试目标不是寻找antlr-4.2-complete.jar
。我该如何解决这个问题?
这是我的 POM 文件:
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.048 sec <<< FAILURE!
checkGrammar(br.com.stoneage.GrammarTest) Time elapsed: 0.011 sec <<< ERROR!
java.lang.NoClassDefFoundError: org/antlr/v4/runtime/CharStream
Run Code Online (Sandbox Code Playgroud) 基本上我有一个 Maven 项目,我试图使用mvn clean compile package
下面的 pom.xml 通过 spring 工具套件生成我的项目的 jar。
执行命令后,我的target
文件夹中生成了 2 个 jar 文件 - {project-name}.jar 和 {project-name}.jar.original
该.jar
文件包含
具有此内容的Spring boot 框架类文件,而该文件包含我的应用程序的实际类文件。.jar.original
我也尝试过使用,mvn clean install
但没有成功。此外,仅安装了 1 个文件,这对我来说毫无用处,因为它不包含class
我的应用程序的任何文件,但包含 spring 框架类。
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>com.commonporject</groupId>
<artifactId>commonporject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>commonporject</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties> …
Run Code Online (Sandbox Code Playgroud) 我有一个使用 Maven 的 Java 项目。在我的项目中,我有一个名为的文件夹libs
,其中包含我无法从 Internet/外部存储库加载的所有 JAR。
我的问题是如何指定 Maven 在打包、构建等过程中包含这些 JAR?
Maven 新手,抱歉,如果这是一个愚蠢的问题。
编辑:我有一个自动工具,可以pom.xml
在我的 Git 上查找我的项目,以在不同的环境中构建和部署我的项目。因此,按照此处的建议将其添加到本地 Maven 存储库中将无济于事,因为它只能在我的 PC 上运行。如果我添加一个libs
带有 JAR的文件夹,无论我在哪里,它都可以使用。
如果不清楚或者我弄错了,请在评论中问我。
我在我的项目中使用 Maven。如果我的项目不使用某些本地资源,这不是问题。因此,我按照本指南 /sf/answers/4310368121/ 将本地 jar 复制到本地 Maven 存储库并由 Maven 进行验证。
正如您所看到的,在 中maven-install-plugin
,我设置为在clean
阶段安装本地存储库。这意味着mvn clean
,maven 会将我的 jar 复制到 maven 本地存储库。
问题是,如果我分别运行mvn clean
和mvn install
两个命令 => 没有问题如果我运行mvn clean install
=> 构建失败,如日志所示
Caused by: org.apache.maven.project.DependencyResolutionException: Could not resolve dependencies for project xxxx:xxxx:war:0.0.1-SNAPSHOT: Failure to find org.xxxx:xxxx-ws:jar:1.0.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
Run Code Online (Sandbox Code Playgroud)
看起来默认情况下,maven 总是执行以下顺序:验证>编译>清理>安装。我也尝试过“mvn clean …
我是 Maven 新手,我想将SSJ库添加到 Maven 项目中的依赖项中,我尝试在 POM.xml 中添加以下内容:
<dependency>
<groupId>ca.umontreal.iro</groupId>
<artifactId>ssj</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
但 eclipse 给出了这个错误:Missing artifact ca.umontreal.iro:ssj-2.5
似乎在存储库中找不到它。我有 jar 文件,如何将其添加到依赖项中?如果可能的话。如果没有,将这个 jar 包含在项目中的替代方案是什么?
我创建了一个可运行的jar,并将其包含在我的项目(Maven项目)中。但是当我尝试做mvn clean package时。我的构建失败了我的一个类导入给我一个错误,指出该包不存在(jar中存在)。
我试过的
错误信息:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project interplan: Compilation failure: Compilation failure:
[ERROR] ..\..\..\MyVehicles.java:[11,40] error: package com.vehicles.parts.manager does not exist
Run Code Online (Sandbox Code Playgroud)
请指导。提前致谢。
我在 eclipse 中创建了一个 Maven 项目,我想将它部署在服务器上(我猜是 tomcat)。我相信这可以通过 Spring Boot 来完成。我的问题是:这个项目导入了位于我的电脑上的几个 jar 文件,并且在其构建路径的工作区中还有另一个项目。我担心在集成(将其变成 Maven)期间我可能会丢失所有依赖项。通常将 jar 文件导入项目的最佳方法是什么以及如何在其构建路径中添加另一个项目?请评论您需要的任何其他规格。
这是pom.xml
<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>org.apache.jena</groupId>
<artifactId>jena-examples</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Apache Jena - Code Examples</name>
<description>A collection of example code illustrating uses of Apache Jena</description>
<url>http://jena.apache.org/</url>
<properties>
<ver.jena>[3.1.0,)</ver.jena>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<organization>
<name>Apache Software Foundation</name>
<url>http://apache.org</url>
</organization>
<dependencies>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>apache-jena-libs</artifactId>
<version>${ver.jena}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.4.9</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.6</version>
</dependency> …
Run Code Online (Sandbox Code Playgroud) mvn install后生成jar。无法在 Windows 上使用 Loader.loadNativeLibraries()。
ortools的版本是9.0.9048。我在windows上用过。我将以下两个 jar 添加到项目中,并按照链接所述添加它们。
然后这两个jar就在IDEA的这里了。
pom文件如下:
然后我就可以在IDEA中正常运行程序了。但是当我 mvn install 生成 jar 文件并通过 'java -jar jarfile.jar' 运行 jar 时,出现错误:
它说 java.nio.file.NoSuchFileException: /BOOT-INF/lib/ortools-win32-9.0.jar!/win32-x86-64/ ,但是当我在 winrar 中打开 jar 时,它存在。
有谁知道原因吗?
我正在写Spring应用程序,我有两个外部罐子.它在IDE中工作,但是当我用maven构建可执行jar时,它失败了,错误java.lang.NoClassDefFoundError:到我的外部jar.我用Google搜索,但我仍然不知道该怎么做.请帮我.我对pom文件的依赖是:
<dependency>
<groupId>com.myapp.myappawsprovider</groupId>
<artifactId>MyAppProvider</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>/Users/Projects/Java/MyApp/MyAppProvider/target/MyAppProvider Provider-1.0.0.jar</systemPath>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我用男士包装来构建它.
长话短说
<importedGroupid>:<importedArtifactid>:jar:1.0
Maven在存储库中找不到file://<homeDirectory>/.m2/repository/
。包裹实际上在<homeDirectory>/.m2/repository/<importedGroupid>/<importedArtifactid>/1.0/
我并不认为自己理解 Maven,但我能想到的两个潜在原因是:
:
它会与and混淆/
(即 UNIX 风格的路径分隔符与:
Maven 中的任何含义),或者:
和/
实际上被解释为相同,则它搜索的路径包括jar
实际目录结构中不存在的另一个子目录级别。详细说明
我试图在 Maven 中本地导入一个包(因为该包没有在线部署)。stackoverflow 上的各种答案(例如,this和thismvn install
)建议在包含包的 jar 上运行,如下所示(假设 jar 位于/usr/share/java
,版本为 1.0 等):
mvn install:install-file -Dfile=/usr/share/java/<importedArtifactid>-1.0-SNAPSHOT.jar -DgroupId=<importedGroupid> -DartifactId=<importedArtifactid> -Dversion=1.0 -Dpackaging=JAR -DgeneratePom=true
Run Code Online (Sandbox Code Playgroud)
并通过添加以下内容在当前包中定义它pom.xml
:
<repository>
<id>repository</id>
<url>file://${user.home}/.m2/repository/</url>
</repository>
Run Code Online (Sandbox Code Playgroud)
该mvn install
命令将包部署到<homeDirectory>/.m2/repository/
. 到目前为止,这工作得很好:
<prompt> $ mvn install:install-file -Dfile=/usr/share/java/<importedArtifactid>-1.0-SNAPSHOT.jar -DgroupId=<importedGroupid> -DartifactId=<importedArtifactid> -Dversion=1.0 -Dpackaging=JAR -DgeneratePom=true
[INFO] Scanning for projects...
[INFO] …
Run Code Online (Sandbox Code Playgroud) java ×10
maven ×8
dependencies ×2
jar ×2
maven-3 ×2
spring ×2
spring-boot ×2
antlr ×1
build ×1
deployment ×1
eclipse ×1
maven-2 ×1
or-tools ×1
pom.xml ×1
repository ×1