java - Maven 无法识别添加的软件包
问题描述
我第一次用 Maven 开发一个项目。我有一个外部包,我已将其转换为 .jar 文件并安装到 maven 中以使用它的类。但是,即使包已经在 .m2 文件夹中,maven 仍然说它找不到包(util):
[ERROR]/home/luis/Desktop/git/sifu/Challenges/Java/java_0002_SN/stringNorm/src/main/java/stringNorm/MyDetector.java:[14,27] cannot find symbol
symbol: class report
location: class stringNorm.MyDetector
[ERROR]/home/luis/Desktop/git/sifu/Challenges/Java/java_0002_SN/stringNorm/src/main/java/stringNorm/MyDetector.java:[9,1] package util does not exist
[ERROR]/home/luis/Desktop/git/sifu/Challenges/Java/java_0002_SN/stringNorm/src/main/java/stringNorm/MyDetector.java:[19,23] cannot find symbol
symbol: class report
location: class stringNorm.MyDetector
我已经尝试将这个新的依赖项(util)添加到 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>
<groupId>com.sifu</groupId>
<artifactId>stringNorm</artifactId>
<version>1.0</version>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spotBugsVersion>4.0.0</spotBugsVersion>
</properties>
<description>My SpotBugs plugin project</description>
<dependencies>
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs</artifactId>
<version>${spotBugsVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>util</groupId>
<artifactId>util</artifactId>
<version>1.0.0</version>
<scope>system</scope>
</dependency>
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>test-harness</artifactId>
<version>${spotBugsVersion}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<version>1.0.2</version>
<executions>
<execution>
<id>validate-spotbugs-configuration</id>
<goals>
<goal>validate</goal>
</goals>
<configuration>
<validationSets>
<validationSet>
<dir>src/main/resources</dir>
<includes>
<include>findbugs.xml</include>
</includes>
<systemId>findbugsplugin.xsd</systemId>
</validationSet>
<validationSet>
<dir>src/main/resources</dir>
<includes>
<include>messages.xml</include>
</includes>
<systemId>messagecollection.xsd</systemId>
</validationSet>
</validationSets>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs</artifactId>
<version>${spotBugsVersion}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
正如您从代码片段中看到的那样,我正在使用 spotbugs 对我的代码进行分析。我要使用的单元包中的类是报告类,我的导入语句看起来像这样 `import util.*;
我使用以下命令将我的 jar 文件安装到 maven:mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
完成后,我将其添加到 pom 文件中。
我的 util 包由 3 个类组成,我jar cfv util.jar *
在 util 文件夹中做了,并给了我一个 jar 文件。
解决方案
推荐阅读
- python - pandas.DataFrame.replace() method doesn't replace anything when using a variable in regex
- swift - How can I export my already made CSV to my Iphone?
- javascript - Check if time is in the range in nodejs
- php - Why do I use Laravel collect() instead of simple PHP function?
- reactjs - Pop up menus getting covered when using react-infinite-scroller component
- reactjs - REACT SWIPER 不显示图像
- webrtc - PeerJS 数据通道分块数据未按顺序到达
- javascript - 如何在控制台中更改具有类名“图像”的样式属性的值?
- database - 具有灵活类型的 GraphQL 查询
- javascript - 围绕中心点旋转对象坐标