Linux compiles Java and packages

Source: Internet
Author: User

First, to compile a simple Java file (do not refer to the external jar package) such as Test.java

public class Test () {System.out.println ("Hello world!");}
A simple class to see how it is packaged as a jar

1. First step: Compile first

Javac Test.java//Note path

A test.class file is generated after compilation

2. Step Two:

JAR-CVF Test.jar Test.class


Two. If you are referencing an external jar package, how to package it

I take the example of Wordcount,java in Hadoop:

The instructions can be written as script execution:

The script is as follows:

#!/bin/bash

hadoop_version=1.1.2

Hadoop_home=/usr/local/hadoop//hadoop Installation path

Hadoop-core-1.1.2.jar package path under Lib=${hadoop_home}/hadoop-core-${hadoop-version}.jar//HADOOP

mkdir My_wordcount

JAVAC-CP $Lib-D my_wordcount wordcount.java//compile Wordcount.java Genetic class file into the My_wordcount folder $Lib referencing jar Packages

JAR-CVF Wordcount.jar my_wordcount/. Package into Wordcount.jar with the class file under the My_wordcount file


Linux compiles Java and packages

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.