search
HomeJavaJavagetting StartedThere is a detailed introduction to the operation of jar packages in java

There is a detailed introduction to the operation of jar packages in java

Why use jar package and what is jar package

After the .java file is compiled, a .class file is generated. If it is written directly in other programs Or it would be inconvenient to provide it to others, so package some .class files into a jar package. The jar package can also contain some resource files (such as txt files, html files, css files, etc.), and a manifest file META -INF/MANIFEST.MF.

.class file is platform independent, so the jar package is cross-platform. If it is an executable jar package, the manifest file will contain the Main-Class attribute, indicating the Main method entry.

How to build a jar package

There are two classes as follows, Welcome class and Teacher class

package com.imooc.jardemo1;
import com.imooc.jardemo1.impl.Teacher;;

public class Welcome {
	public int num;
	public static void main(String[] args) {
		Teacher.greeting();
		Welcome welcome=new Welcome();
		Teacher lee=new Teacher();
		welcome.addTeacher(lee, 1, "gil");
		welcome.getTeaInfor(lee);
	}
	public void addTeacher(Teacher teacher,int id,String name) {
		teacher.id=id;
		teacher.name=name;
	}
	public void getTeaInfor(Teacher teacher) {
		String str="ID:"+teacher.id+" Name:"+teacher.name;
		System.out.println(str);
	}
}
rrree

Recommended online video tutorial: java learning Video

Right-click the project-Export

There is a detailed introduction to the operation of jar packages in java

Select Runnable Jar file

There is a detailed introduction to the operation of jar packages in java

The picture below The first box selects the entry file, the second box is the location and name of the exported Jar package, click Finish

There is a detailed introduction to the operation of jar packages in java

to complete the packaging.

How to use the jar package

Create a new folder lib in the project directory: New->Folder, file name lib, you will need to use Copy the jar package into it

There is a detailed introduction to the operation of jar packages in java

#Add the jar package to the build path: Right-click on the jar package that needs to be used->Build path->Add to build Path

There is a detailed introduction to the operation of jar packages in java

Writing the test class JarTest, you can use the classes, methods, etc. in the Jar package (will be automatically imported)

package com.imooc.jardemo1.impl;

public class Teacher {
	public String name;
	public int id;
	public static void greeting() {
		System.out.println("Welcome!");
	}	
}

Summary:

The advantage of using jar packages is to package a bunch of files into one file for easy use.

This article is recommended to everyone by the java introduction column. You can come to this column to communicate and learn together.

The above is the detailed content of There is a detailed introduction to the operation of jar packages in java. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:CSDN. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment