Запустить класс Java с внешними зависимостями из командной строки?JAVA

Программисты JAVA общаются здесь
Ответить
Гость
 Запустить класс Java с внешними зависимостями из командной строки?

Сообщение Гость »


Мне интересно, можно ли запустить класс Java, использующий внешние библиотеки, с помощью командной строки Windows.
У меня есть следующий минимальный пример класса Java, где я просто использую library to create a JSON file using the

Код: Выделить всё

ObjectMapper
class:

Код: Выделить всё

import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
import java.io.IOException;

public class Test
{
public static void main(String[] args) throws IOException
{
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.writeValue(new File("test.json"), "test");

System.out.println("Finished!");
}
}
I compiled this project originally using Maven in the IntelliJ IDE, and I set the proper dependencies for in the file.
I then wanted to run the resultant

Код: Выделить всё

Test.class
file with the Command Prompt with the following command:

Код: Выделить всё

java Test
Resulting in:

Код: Выделить всё

Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
at Test.main(Test.java:9)
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ObjectMapper
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
... 1 more
I'm not very experienced with Java, and I've only ever used IDEs that handle most of the linking in the background for me. I just know that one can run a Java class in the Windows CMD using the command, and I'm assuming that here it's telling me that it can't link the library properly.
Most of the existing simillar questions out there usually ask about user-made classes, I haven't yet been able to find a solution for external dependencies such as those defined by Maven.
Is it possible to run a Java class that uses external libraries using the Windows Command Prompt?
Thanks for reading my post, any guidance is appreciated.


Источник: https://stackoverflow.com/questions/781 ... and-prompt
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»