简体   繁体   English

在 Intellij (Java) 中使用命令行编译时如何修复“错误:com.fasterxml.jackson.databind 包不存在”

[英]How to fix "error: package com.fasterxml.jackson.databind does not exist" when compiling using command line in Intellij (Java)

I have been trying to compile my Java code using the format javac Main.java but for some reason the compiler says that my package does not exist and as a matter of fact it is in the project structure, here is a screenshot:我一直在尝试使用javac Main.java格式编译我的 Java 代码,但由于某种原因,编译器说我的包不存在,事实上它在项目结构中,这是一个屏幕截图:

我的代码的文件结构

The exact error is: Main.java:1: error: package com.fasterxml.jackson.databind does not exist import com.fasterxml.jackson.databind.ObjectMapper;确切的错误是: Main.java:1: error: package com.fasterxml.jackson.databind does not exist import com.fasterxml.jackson.databind.ObjectMapper;

And my code looks like this in my Main.java:我的代码在我的 Main.java 中如下所示:

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneId;


public final class Main {
    public static void main(String[] args) throws Exception {
        if (args.length != 1) {
            System.out.println("Usage: Main [file path]");
            return;
        }

        UdacisearchClient client =
                new UdacisearchClient(
                        "CatFacts LLC",
                        17,
                        8000,
                        5,
                        Instant.now(),
                        Duration.ofDays(180),
                        ZoneId.of("America/Los_Angeles"),
                        "555 Meowmers Ln, Riverside, CA 92501");

        Path outputPath = Path.of(args[0]);
        
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.registerModule(new JavaTimeModule());
        objectMapper.writeValue(Files.newBufferedWriter(outputPath), client);

        System.out.println("Wrote to: "+ outputPath.toAbsolutePath());
        UdacisearchClient deserialized = objectMapper.
                readValue(Files.newBufferedReader(outputPath), UdacisearchClient.class);

        System.out.println("Deserialized: " + deserialized);

    }
}

The whole code is supposed to compile like this javac Main.java and then java Main client.json .整个代码应该像这样javac Main.java然后java Main client.json When I try to compile it by going to Run , Edit Configurations and by adding client.json as the argument of my program it works like a charm, my object is serialized as a json object in the client.json file but when I compile using command line it says no package is found.当我尝试通过转到RunEdit Configurations并通过添加client.json作为我的程序的参数来编译它时,它就像一个魅力,我的对象在client.json文件中被序列化为一个 json 对象但是当我使用编译时命令行它说没有找到包。 The same error happens for any other dependency I try to use.我尝试使用的任何其他依赖项都会发生相同的错误。 It should be noted that when I instantiate objects from my dependency it looks fine as the import lines related to those objects aren't red.应该注意的是,当我从我的依赖项中实例化对象时,它看起来很好,因为与这些对象相关的import行不是红色的。 So I guess my issue resides in my command line compilation or my Intellij environment.所以我想我的问题在于我的命令行编译或我的 Intellij 环境。 I have tried many of the solution proposed online but the problem remains.我已经尝试了许多在线提出的解决方案,但问题仍然存在。 I would like some help please.我需要一些帮助。

It turns out the solution was simple.事实证明,解决方案很简单。

First compiling the libraries inside the lib folder and Main.java doing :首先编译lib文件夹和Main.java中的库:

javac -cp ".;lib/*" Main.java

Then running my class Main (containing my main function):然后运行我的Main类(包含我的main函数):

java -cp ".;lib/*" Main

I was missing on the dot " . " and the semicolon ;我缺少点“ . ”和分号 !

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:编译 Java 文件时“包 com.fasterxml.jackson.databind 不存在” - Error: "package com.fasterxml.jackson.databind does not exist" when compiling Java file package com.fasterxml.jackson.databind 不可访问 Java (268436910) - The package com.fasterxml.jackson.databind is not accessible Java (268436910) 如何解决(在 com.fasterxml.jackson.databind)错误 - How to solve (at com.fasterxml.jackson.databind) error 使用 com.fasterxml.jackson.databind 无法识别的字段 - Unrecognized field using com.fasterxml.jackson.databind 如何在不使用 @JsonIgnore 的情况下解决 (com.fasterxml.jackson.databind) 异常 - How to solve (com.fasterxml.jackson.databind) Exception with out using @JsonIgnore 出现错误:java: package com.fasterxml.ZB41779690B83F18AC9Zannotation 不存在 - There is Error: java: package com.fasterxml.jackson.annotation no exist 编译报错package com.fasterxml.jackson.annotation不存在 - Compilation error package com.fasterxml.jackson.annotation does not exist 使用杰克逊将XML映射到Java时出错:com.fasterxml.jackson.databind.exc.MismatchedInputException - Error while mapping xml to java using jackson: com.fasterxml.jackson.databind.exc.MismatchedInputException 如何修复“com.fasterxml.jackson.databind.JsonMappingException:反序列化属性问题”错误 - How to fix 'com.fasterxml.jackson.databind.JsonMappingException: Problem deserializing property' error 如何解决 com.fasterxml.jackson.databind.ser 错误 - How To Solve com.fasterxml.jackson.databind.ser Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM