Linux consolidation record (1) compilation and execution of Java projects

Source: Internet
Author: User

It's a lot more time to operate Linux due to the recent use of Hadoop and other related tasks.

Previously, only the Java EE Project execution Environment was configured on Linux, with the provision of a JDK, deployment of Tomcat, and automatic deployment via Docker or Jenkins

Look at the process, copy and paste deletion and other basic operations, a lot of things for a long time forget, all write a demo to consolidate the Linux knowledge

Follow-up will be the mainstream of Hadoop and other major data-related environment to build and use

--------------------------------------------------------------------------------------------------------------- ------------------------------------------

This time, the most basic Java compilation

1. Compilation and operation of a single Java file

A first view the directory structure via the tree command (available via yum-y install tree online)

[Email protected] javafile]# tree.├──lib│├──commons-io-2.5.jar│└──spring-core-4.3.9.release-sources.jar└──src
    └──test        

A single file if there is a package that needs to follow the-D compilation to store the path

If other jar packages are referenced, use-classpath to indicate that multiple jar packets are separated by colons

For example, I need to refer to two jar packages in my test, and it is under the test package

Package Test;import Java.io.file;import Java.io.ioexception;import org.apache.commons.io.fileutils;import Org.springframework.util.stringutils;public class Iotest {public    static void Main (string[] args) throws IOException {        file F = new File ("/input.txt");        System.out.println (F.getabsolutepath ());        String result = Fileutils.readfiletostring (f);        SYSTEM.OUT.PRINTLN (result);                if (Stringutils.isempty (Result)) {            System.out.println ("Empty File");        } else {            System.out.println ("Non-empty File");        }    }}

Then the compile command should be as follows

[Email protected] javafile]# Javac-classpath.:/ home/javafile/lib/*-d/home/classes//home/javafile/src/test/iotest.java Note:/home/javafile/src/test/iotest.java Uses or overrides a deprecated API. Note:recompile with-xlint:deprecation for details. [Email protected] javafile]# tree/home/classes//home/classes/├──org│└──springframework│     └──util│         ├──a ssert.class│         ├──collectionutils.class│         ├──collectionutils$enumerationiterator.class│         ├── collectionutils$multivaluemapadapter.class│         ├──multivaluemap.class│         ├──objectutils.class│         └── Stringutils.class└──test    

After compiling, you should follow the following command:

2. Compiling multiple Java files or Java projects

After 1 of the code, a simple modification, iotest need to call the code in Testutil

 Packagetest;ImportJava.io.File;Importjava.io.IOException;Importorg.apache.commons.io.FileUtils;Importorg.springframework.util.StringUtils;import Xiao.util.TestUtil; Public classIotest { Public Static voidMain (string[] args)throwsIOException {File f=NewFile ("/input.txt");        System.out.println (F.getabsolutepath ()); String result=fileutils.readfiletostring (f);        SYSTEM.OUT.PRINTLN (result); if(Stringutils.isempty (Result)) {System.out.println ("Empty File"); } Else{System.out.println ("Non-empty file"); } testutil.test ( "Main msg"); }}
 Package Xiao.util;  Public class Testutil {    publicstaticvoid  Test (String s) {        System.out.println ( "util:" + s);    }      Public Static void Main (string[] args) {        test ("Test utils msg");}    }

A first view the directory structure via the tree command (available via yum-y install tree online)

[Email protected] javafile]# tree.├──lib│├──commons-io-2.5.jar│└──spring-core-4.3.9.release-sources.jar└──src
    ├──test    │└──iotest.java    └──xiao        └──util            

B. Generating a list of files that need to be compiled

C. Start compiling

[Email protected] javafile]# Javac-classpath.:/ home/javafile/lib/*-d/home/classes/@/home/javafile/needcompilejavafiles.txt Note:src/test/iotest.java uses or Overrides a deprecated API. Note:recompile with-xlint:deprecation for details. [Email protected] javafile]# tree/home/classes//home/classes/├──org│└──springframework│     └──util│         ├──a ssert.class│         ├──collectionutils.class│         ├──collectionutils$enumerationiterator.class│         ├── collectionutils$multivaluemapadapter.class│         ├──multivaluemap.class│         ├──objectutils.class│         └── Stringutils.class├──test│└──iotest.class└──xiao    └──util        

D Run Code

[Email protected] javafile]# java-classpath/home/classes/:/home/javafile/lib/*

Results match expectations

PS Web projects do not build themselves under Linux, copying too many things,

Just copy it through other tools like Jenkins or Maven.

Because Java cross-platform O (∩_∩) o haha ~

Linux consolidation record (1) compilation and execution of Java projects

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.