简体   繁体   English

在netbeans中使用外部jar依赖项

[英]using external jar dependency in netbeans

I am trying to create a web application on Netbeans by using Springboot which will generate all the necessary dependencies needed. 我正在尝试使用Springboot在Netbeans上创建一个Web应用程序,该应用程序将生成所需的所有必需依赖项。 My project will use an external API that I converted into a single jar class from https://github.com/coinapi/coinapi-sdk/tree/master/java-rest which was compiled into multiple class files and then into a single jar file called CoinAPI. 我的项目将使用我从https://github.com/coinapi/coinapi-sdk/tree/master/java-rest转换为单个jar类的外部API,该API被编译为多个类文件,然后转换为单个jar名为CoinAPI的文件。 I then added the jar to my local repository via 然后,我通过以下方式将罐子添加到本地存储库中

mvn install:install-file -Dfile=.\com\coinapi\CoinAPI.jar -DgroupId=com.coinapi
-DartifactId=CoinApi -Dversion=1.0.1 -Dpackaging=jar

which was sucessfully added I then added this jar to my pom.xml which displayed 成功添加了它,然后将这个jar添加到显示的pom.xml中

<?xml version="1.0" encoding="UTF-8"?>
<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.alyxdev</groupId>
    <artifactId>CryptoStat</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>CryptoStat</name>
    <description>CryptoCurrency Analytics</description>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.RELEASE</version>
        <relativePath/>
        <!-- lookup parent from repository -->
    </parent>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.M8</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-aws</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-aws-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-aws-messaging</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.36</version>
        </dependency>

        <dependency>
          <groupId>com.coinapi</groupId>
          <artifactId>CoinAPI</artifactId>
          <version>1.0.1</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
            <version>2.7.8</version>
            <type>jar</type>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
</project>

It successfully builds so I then try to utilize some of the classes inside the external library with the following: 它成功构建,因此我然后尝试通过以下方法利用外部库中的一些类:

package com.alyxdev.cryptostat;

import com.coinapi.java_rest_coin_api;



/**
 *
 * @author Alyx
 */
public class CoinAPIConnector {

    public CoinAPIConnector(){

    }
    public void initConnect(){

        java_rest_coin_api connect = new java_rest_coin_api("BEA6B82A-2489-4B5F-8B28-157A627DC8A1");

    }

}

however for some reason I get an error with my import which says "cannot find symbol: class java_rest_coin_api location: package com.coinapi" 但是由于某种原因,我的导入出现错误,提示“找不到符号:类java_rest_coin_api位置:包com.coinapi”

I want to know if I am incorrectly using the external dependency when I import it or is my import somehow incorrect. 我想知道我在导入时是否错误地使用了外部依赖关系,或者我的导入在某种程度上是不正确的。

On the first look, your pom file looks good. 乍看之下,您的pom文件看起来不错。 So I will suggest to open in your NetBeans the Project view and find the Dependencies item. 因此,我建议在您的NetBeans中打开“项目”视图并找到“ 依赖项”项。 Then you can click on it, and search for your CoinAPI library. 然后,您可以单击它,并搜索您的CoinAPI库。 Then you can expand it and find out if the required class is on the list inside. 然后,您可以展开它并找出所需的类是否在列表中。

There's also another issue. 还有另一个问题。 The CoinAPI uses additional libraries: json-20140107.jar, okhttp-3.8.1.jar, okio-1.13.0.jar. CoinAPI使用其他库:json-20140107.jar,okhttp-3.8.1.jar,okio-1.13.0.jar。

I bet you need to add them as dependencies to your pom file. 我敢打赌,您需要将它们作为依赖项添加到pom文件中。 Fortunately, most of them are already published on the central maven repo (at least ok libs). 幸运的是,它们中的大多数已经发布在中央Maven存储库中(至少是OK库)。

Ok so I found the solution to add the library as a dependency. 好的,所以我找到了将库添加为依赖项的解决方案。 I created a new java library project on netbeans (instead of building the jar on the command line and externally adding it to the project with mvn install) then I added the sources files there and then built the project to create the jar files. 我在netbeans上创建了一个新的Java库项目(而不是在命令行上构建jar,并通过mvn install从外部将其添加到项目中),然后在其中添加了源文件,然后构建了项目以创建jar文件。 I then modified my pom.xml to an updated version of the project and finally went to the dependencies right click on the the jar and clicked on manually install artifact and found the jar on my netbeans workbench. 然后,我将pom.xml修改为项目的更新版本,最后右键单击jar上的依赖项,然后单击手动安装工件,然后在netbeans工作台上找到jar。 After that I just had to refresh my project and the errors were gone. 之后,我只需要刷新我的项目,错误就消失了。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM