我需要解析我的maven项目中的一个json文件。为此,我在我的java文件(App.java)中开始了一个简单的导入。
package com.mycompany.app;
import com.fasterxml.jackson.*;// <-------- HERE
public class App
{
public static void main( String[] args )
{
}
}
然后,我尝试使用mvn package
编译项目,但出现错误:
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< com.mycompany.app:my-app >----------------------
[INFO] Building my-app 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ my-app ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /tmp/my-app/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ my-app ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /tmp/my-app/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /tmp/my-app/src/main/java/com/mycompany/app/App.java:[2,1] package com.fasterxml.jackson does not exist
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.628 s
[INFO] Finished at: 2022-05-10T15:31:39+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project my-app: Compilation failure
[ERROR] /tmp/my-app/src/main/java/com/mycompany/app/App.java:[2,1] package com.fasterxml.jackson does not exist
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
下面是我如何构建我的Maven项目:
1.我创建了我的maven项目:
mvn -B archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4
1.我修改了文件App.java(由上一个命令创建),使其与我的文件匹配。
1.我修改了pom.xml以添加依赖项:
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.2</version>
</dependency>
您知道如何解决此错误吗?
1条答案
按热度按时间6ie5vjzr1#
我最近已经answered了一个类似的问题:问题是
com.fasterxml.jackson
不是一个包,存在一个文件夹com/fasterxml/jackson
(参见source),但不是一个包。在Java中,package
是一个包含至少一个类的命名空间。Asterix import non-recursively 导入包中的所有类。所以,如果你需要,比方说,要使用com.fasterxml.jackson.core
包中的JsonParser.java
和JacksonException.java
类,您可以添加一个asterix导入,如下所示:com.fasterxml.jackson.core.*