"Java" "Go" compile and run Java on the command line

Source: Internet
Author: User

Original: http://blog.csdn.net/u010900574/article/details/50792353 compile multiple jar packages and Java files simultaneously

We often need to compile and run Java files from the command line when we use the code on a regular basis or when we deploy it to a Linux server, and most of the methods on the Web are

javac -cp   filePath/jarName.jar  javaName.java

This method. But joined in the FilePath folder there are several jar packages, in the SRC folder there are several Java files, this method is very clumsy, I look at the online information is very chaotic, in fact, the following a very simple command can be solved:

javac -Djava.ext.dirs=filePath  *.java//注意这里只需要指定到jar包所在的文件夹就可以了

*.javait means that all Java files can be compiled at once.

Place the compiled file in the specified directory

If you want to put the compiled file into the specified directory, just add it to the Java file -d outputFilePath , such as the following:

javac -Djava.ext.dirs=filePath  *.java  -d outputFilePath
Executing Java files

Execute the Java Program page is the same, only need to javac replace java , write the main function in the name of the Java file, do not have to add a suffix. For example, below

javac -Djava.ext.dirs=filePath  MainJavaName

If you want to put the compiled file into the specified directory, just add it to the Java file -d outputFilePath .

Example Demo

Let's take a practical example to demonstrate
Under the Serverprogram folder there is a labrary folder, there are several jar files, SRC is the source package, there are three Java files, the output folder is where I want to export compiled files,

Compilation process

//首先进入Src文件夹javac -Djava.ext.dirs=../Library *.java -d ../Output//指定输出编译文件的位置为上级目录的Output文件夹
Execution process

Enter the output folder first

//主函数所在文件是Server.javajava -Djava.ext.dirs=../Library  Server

"Java" "Go" compile and run Java on the command line

Related Article

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.