Windows/linux the jar package and run it with Javac/java compilation

Source: Internet
Author: User

Windows/linux under the reference jar package, and Javac/java compiled to run, the need for friends can refer to the next.

1> Windows

Suppose the jar to be referenced is placed in the D:/test directory with the name T1.jar, and the Java source file is placed in the D:/TEST/SRC directory with the name T2.java.

Compile:

JAVAC-CP D:/test/t1.jar D:/test/src/t2.java

Run:

JAVA-CP D:/TEST/T1.JAR;D:/TEST/SRC T2

Note that there is no space behind the semicolon, or an error.

It is important to note that if the Java source file is a package, such as the package is com.example, the source file is Com.example.t2.java.

For example, the file storage directory is: D:/test/src/com/example/t2.java, and then for example T1.jar placed under d:/test/lib/, then Javac compile time in the d:/test/directory.

You can specify the build location of the. Class with the-D option.

JAVAC-CP d:/test/lib/t1.jar;classes;. -D Classes Src/com/example/t2.java

2> Linux

Assuming that the jar package is placed in the/home/bill directory, the name T1.jar,java source file is placed in the/HOME/BILL/SRC directory with the name T2.java

Compile:

Javac-cp/home/bill/t1.jar/home/bill/src/t2.java

If you are referencing multiple jars, separate them with colons.

Run:

java-cp/home/bill/t1.jar:/home/bill/src T2

Note that this is a colon delimiter, and there are no spaces behind it.

Windows/linux the jar package and run it with Javac/java compilation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.