How to use the jar package to use third-party libraries (three ways)

Develop a system that requires a lot of third-party libraries (not your own development code): available in the form of jar package

  1. Analysis relies

               maven path dependent: C: \ Users \ dell \ .m2 (generally downloaded installation embodied according to the path to your IDEA)

    2.maven automatically download

         Download slow reasons:

  • Download Source abroad
  • We configured with only a dependent, but may be more practical to download something

       Automatic Configuration Find relation to compile and run stages

  • During the writing, but also need to * .class / *. Java
  • During compilation, the need to * .class
  • During the operation, also need * (loading class) .class

Compile: javac-cp used to tell the compiler where to put the class

During operation: <1.javac-cp used to tell the compiler where to put the class

                  <2. Environment Variables CLASSRPATH

(IDEA marked red occurred during compilation)

maven is a tool that is equivalent to the first and the app store

maven at run time required to keep the network in good condition

jar package (direct programming interface)

jar is the abbreviation for Java ARchive, is a basic format of the zip file format. The goal is to generate java class files, resource files, file management and other packaged in a specific structure into a separate file for easy downloading or web publishing program.

Where to find a good jar package: Search under Github

1. Write your own code is packaged into a jar package

2. Use someone else to write the jar package

Cmd (jar -help to view the document)

Notepad ++ compiler using cmd steps of: switching the input file path letter + + compiler running

 

      The jar packaging: Hello.jar content that I named jar package jar package will be followed by the name of these classes are compressed packed into the bag Hello.jar

 

    Run jar package: the event of error can not find the class, you need to manually specify the location of the class

编译期间: javac -encoding UTF-8 -cp".;Hello.jar" Run.java
 //设置去当前路径或者Hello.jar进行查找类 
运行期间:配置环境变量
 1.查看环境变量:set(所有配置的环境变量)
 2.如何查看具体的环境变量:echo %path%(输出path所代表的的环境变量)
 3.可以使用一次性的环境变量:set classpath=".;jar包名"

 

IDEA

The jar packaging:

  1. file - Project Structuer - Artifacts - "+" - jar - From modules with Dependenceies-- needed to choose whether to fill Main.Class
  2. Build——Build actifacts——build
  3. Run jar package: out - artifacts - jar package - Right-click RUN

Using someone else's jar package;

  1. Using someone else's path: file - Project Structuer-librbrie "+" Select jar package path
  2. And then use the import import

maven

  1. Create a new maven project
  2. The need to be arranged in pom.xml
  3. Be writing code
例如:导入一个jar包(用于在终端上进行图画)
<dependencies>
        <dependency>
        <groupId>org.fusesource.jansi</groupId>
        <artifactId>jansi</artifactId>
        <version>1.18</version>
        </dependency>
</dependencies>

 

 

 

 

 

Published 40 original articles · won praise 4 · Views 861

Guess you like

Origin blog.csdn.net/weixin_44919969/article/details/103889221
Recommended