Ubuntu 上的 maven 的 Java 错误是什么:package org.apache.http.client does not exit import org.apache.http.client.ClientProtocolExcepti?

Ubuntu 上的 maven 的 Java 错误是什么:package org.apache.http.client does not exit import org.apache.http.client.ClientProtocolExcepti?

我在 Ubuntu 上使用 Java 和 Maven 项目,但在 NetBeans IDE 上构建 Java 代码时出现以下错误: package org.apache.http.client does not exist import org.apache.http.client.ClientProtocolException;

我的 Ubuntu 上有以下内容:

sudo which java
/usr/bin/java

sudo echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/>:/snap/bin

sudo mvn -version
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 11.0.17, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.15.0-58-generic", arch: "amd64", family: "unix"

sudo echo $JAVA_HOME
/usr/lib/jvm/java-1.11.0-openjdk-amd64

sudo java -version
openjdk version "11.0.17" 2022-10-18
OpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu220.04)
OpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu220.04, mixed mode, sharing)

sudo javac -version
javac 11.0.17

which mvn
/usr/bin/mvn

我必须包含maven的路径还是其他?

问题编辑以提供清晰的图片:

ant -f /home/kamran/NetBeansProjects -Dnb.internal.action.name=build jar
init:
Deleting: /home/kamran/NetBeansProjects/build/built-jar.properties
deps-jar:
Updating property file: /home/kamran/NetBeansProjects/build/built-jar.properties
Compiling 89 source files to /home/kamran/NetBeansProjects/build/classes
/home/kamran/NetBeansProjects/Multichain API Demo for Students/src/main/java/multichain/command/builders/QueryBuilderCommon.java:14: error: package org.apache.http.client does not exist
import org.apache.http.client.ClientProtocolException;
/home/kamran/NetBeansProjects/Multichain API Demo for Students/src/main/java/multichain/command/builders/QueryBuilderCommon.java:15: error: package org.apache.http.client.methods does not exist
import org.apache.http.client.methods.HttpPost;
/home/kamran/NetBeansProjects/Multichain API Demo for Students/src/main/java/multichain/command/builders/QueryBuilderCommon.java:16: error: package org.apache.http.entity does not exist
import org.apache.http.entity.StringEntity;
/home/kamran/NetBeansProjects/Multichain API Demo for Students/src/main/java/multichain/command/builders/QueryBuilderCommon.java:17: error: package org.apache.http.impl.client does not exist
import org.apache.http.impl.client.CloseableHttpClient;

错误出现在以下类包导入上:

/*
 * Copyright (C) 2017 Worldline, Inc.
 *
 * MultiChainJavaAPI code distributed under the GPLv3 license, see COPYING file.
 * https://github.com/SimplyUb/MultiChainJavaAPI/blob/master/LICENSE
 *
 */
package multichain.object.formatters;

import java.util.List;

import com.google.gson.GsonBuilder;

/**
 * @author Ub - H. MARTEAU
 * @version 2.1
 */
public class GsonFormatters {
    protected static String formatJson(String[] values) {
        final GsonBuilder builder = new GsonBuilder();
        final Gson gson = builder.create();

        return gson.toJson(values);
    }

    protected static String formatJson(List<Object> values) {
        final GsonBuilder builder = new GsonBuilder();
        final Gson gson = builder.create();

        return gson.toJson(values);
    }

    protected static String formatJson(Object value) {
        final GsonBuilder builder = new GsonBuilder();
        final Gson gson = builder.create();
        return gson.toJson(value);
    }
    
    protected static String formatJsonWithCustomBuilder(Object value, GsonBuilder builder) {
        return builder.create().toJson(value);
    }
    
}

我的项目目录列表如下,并且没有 build.xml,因为 BUILD 命令不成功。

.
./target
./target/httpcomponents-client-4.5.14-jar-with-dependencies.jar
./target/archive-tmp
./target/.plxarc
./target/maven-shared-archive-resources
./target/maven-shared-archive-resources/META-INF
./target/maven-shared-archive-resources/META-INF/DEPENDENCIES
./target/maven-shared-archive-resources/META-INF/LICENSE
./target/maven-shared-archive-resources/META-INF/NOTICE
./LICENSE
./pom.xml
./src
./src/main
./src/main/java
./src/main/java/multichain
./src/main/java/multichain/object
./src/main/java/multichain/object/StreamKey.java
./src/main/java/multichain/object/TransactionBase.java
./src/main/java/multichain/object/TransactionWallet.java
./src/main/java/multichain/object/KeyPairs.java
./src/main/java/multichain/object/BalanceAssetGeneral.java
./src/main/java/multichain/object/BalanceWalletTransaction.java
./src/main/java/multichain/object/TxOut.java
./src/main/java/multichain/object/Block.java
./src/main/java/multichain/object/BalanceAsset.java
./src/main/java/multichain/object/AddressBalanceCurrency.java
./src/main/java/multichain/object/MultiChainInfo.java
./src/main/java/multichain/object/BalanceAssetWalletTransaction.java
./src/main/java/multichain/object/TransactionRAWVin.java
./src/main/java/multichain/object/TransactionRAW.java
./src/main/java/multichain/object/TransactionDetail.java
./src/main/java/multichain/object/TransactionRAWVout.java
./src/main/java/multichain/object/TransactionWalletVin.java
./src/main/java/multichain/object/StreamKeyItem.java
./src/main/java/multichain/object/AssetWalletTransaction.java
./src/main/java/multichain/object/AddressBalanceAsset.java
./src/main/java/multichain/object/Address.java
./src/main/java/multichain/object/TransactionWalletVInfo.java
./src/main/java/multichain/object/Item.java
./src/main/java/multichain/object/PermissionDetailed.java
./src/main/java/multichain/object/SignedTransactionRAW.java
./src/main/java/multichain/object/AddressBalanceIssue.java
./src/main/java/multichain/object/MultiBalance.java
./src/main/java/multichain/object/Balance.java
./src/main/java/multichain/object/AddressInfo.java
./src/main/java/multichain/object/TransactionGeneral.java
./src/main/java/multichain/object/TransactionListElement.java
./src/main/java/multichain/object/Permission.java
./src/main/java/multichain/object/AddressBalance.java
./src/main/java/multichain/object/TransactionWalletVout.java
./src/main/java/multichain/object/Transaction.java
./src/main/java/multichain/object/ScriptPubKey.java
./src/main/java/multichain/object/queryobjects
./src/main/java/multichain/object/queryobjects/CustomParamString.java
./src/main/java/multichain/object/queryobjects/DataParamCreate.java
./src/main/java/multichain/object/queryobjects/ParamIssue.java
./src/main/java/multichain/object/queryobjects/RawStreamParam.java
./src/main/java/multichain/object/queryobjects/AssetQuantity.java
./src/main/java/multichain/object/queryobjects/AssetParams.java
./src/main/java/multichain/object/queryobjects/TxIdVout.java
./src/main/java/multichain/object/queryobjects/ParamIssueMore.java
./src/main/java/multichain/object/queryobjects/DataParamStreamItem.java
./src/main/java/multichain/object/queryobjects/DataParamHex.java
./src/main/java/multichain/object/queryobjects/DataParamIssueMore.java
./src/main/java/multichain/object/queryobjects/DataParam.java
./src/main/java/multichain/object/queryobjects/RawParam.java
./src/main/java/multichain/object/queryobjects/DataParamIssue.java
./src/main/java/multichain/object/StreamKeyInfo.java
./src/main/java/multichain/object/formatters
./src/main/java/multichain/object/formatters/GrantFormatter.java
./src/main/java/multichain/object/formatters/HexFormatter.java
./src/main/java/multichain/object/formatters/MultiChainInfoFormatter.java
./src/main/java/multichain/object/formatters/AddressFormatter.java
./src/main/java/multichain/object/formatters/TxOutFormatter.java
./src/main/java/multichain/object/formatters/TransactionFormatter.java
./src/main/java/multichain/object/formatters/WalletTransactionFormatter.java
./src/main/java/multichain/object/formatters/RAWTransactionFormatter.java
./src/main/java/multichain/object/formatters/BlockFormatter.java
./src/main/java/multichain/object/formatters/BalanceFormatter.java
./src/main/java/multichain/object/formatters/StreamFormatter.java
./src/main/java/multichain/object/formatters/CustomParamFormatter.java
./src/main/java/multichain/object/formatters/GsonFormatters.java
./src/main/java/multichain/object/Stream.java
./src/main/java/multichain/object/Create.java
./src/main/java/multichain/object/MultiChainRPCAnswer.java
./src/main/java/multichain/object/TransactionWalletDetailed.java
./src/main/java/multichain/object/ScriptSig.java
./src/main/java/multichain/TestClass.java
./src/main/java/multichain/command
./src/main/java/multichain/command/WalletTransactionCommand.java
./src/main/java/multichain/command/builders
./src/main/java/multichain/command/builders/QueryBuilderAddress.java
./src/main/java/multichain/command/builders/QueryBuilderRAWTransaction.java
./src/main/java/multichain/command/builders/QueryBuilderBlock.java
./src/main/java/multichain/command/builders/QueryBuilderMining.java
./src/main/java/multichain/command/builders/QueryBuilderIssue.java
./src/main/java/multichain/command/builders/QueryBuilderWalletTransaction.java
./src/main/java/multichain/command/builders/QueryBuilderMessaging.java
./src/main/java/multichain/command/builders/QueryBuilderChain.java
./src/main/java/multichain/command/builders/QueryBuilderBalance.java
./src/main/java/multichain/command/builders/QueryBuilderGrant.java
./src/main/java/multichain/command/builders/QueryBuilderCommon.java
./src/main/java/multichain/command/builders/QueryBuilderKey.java
./src/main/java/multichain/command/builders/QueryBuilderStream.java
./src/main/java/multichain/command/AddressCommand.java
./src/main/java/multichain/command/tools
./src/main/java/multichain/command/tools/MultichainTestParameter.java
./src/main/java/multichain/command/RuntimeParameters.java
./src/main/java/multichain/command/MultichainException.java
./src/test
./src/test/java
./src/test/java/multichain
./src/test/java/multichain/command
./src/test/java/multichain/command/AddressCommandTest.java
./src/test/java/multichain/command/TestConst.java
./Archi.png
./.gitignore
./README.md
./install.sh
./?
find: ‘build.xml’: No such file or directory

项目 $ mvn clean install -X 的 install.sh 命令的输出日志如下所示: https://pastebin.pl/view/645b33d7

Netbeans Java Ant 编译日志 https://pastebin.pl/view/b06c719c

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>com.multichainjavaapi</groupId>
    <artifactId>MultiChainJavaAPI</artifactId>
    <version>0.4.17-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
        <xmlrpc-client.version>3.1.3</xmlrpc-client.version>
        <httpclient.version>4.3.6</httpclient.version>
        <gson.version>2.8.1</gson.version>
        <commons-codec.version>1.10</commons-codec.version>
        <commons-collections4.version>4.1</commons-collections4.version>
    </properties>

    <scm>
        <connection>scm:git:git://github.com/SimplyUb/MultiChainJavaAPI.git</connection>
        <developerConnection>scm:git:[email protected]/SimplyUb/MultiChainJavaAPI.git</developerConnection>
        <url>https://github.com/SimplyUb/MultiChainJavaAPI</url>
    </scm>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin.version}</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
              <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                  <execution>
                    <phase>package</phase>
                    <goals>
                      <goal>single</goal>
                    </goals>
                  </execution>
                </executions>
                <configuration>
                  <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                  </descriptorRefs>
                </configuration>
              </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.apache.xmlrpc</groupId>
            <artifactId>xmlrpc-client</artifactId>
            <version>${xmlrpc-client.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>${httpclient.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>${gson.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>${commons-codec.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-collections4</artifactId>
            <version>${commons-collections4.version}</version>
        </dependency>
        
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>

        </dependency>       
    </dependencies>
</project>

相关内容