Compile Java Codes in Linux Shell instead of Ant Script
The following is frequently used ant script, compile some java source codes with a libary path, then copy all non-java files to compiled folder:
<property name="src.dir" value="${basedir}/src" />
<property name="src.class.dir" value="${webroot.dir}/web-inf/classes" />
<path id="lib.path">
<fileset dir="${webroot.dir}/web-inf/lib">
<include name="**/*.jar" />
</fileset>
</path>
<target name="compile-src" depends="init" description="compile java sources">
<javac srcdir="${src.dir}" destdir="${src.class.dir}" encoding="utf-8"
debug="true" classpathref="lib.path" failonerror="false"/>
<copy todir="${src.class.dir}">
<fileset dir="${src.dir}">
<exclude name="**/*.java" />
</fileset>
</copy>
</target>
The corresponding shell script is:
src_dir=/vagrant/codes/GCP6.1/src
web_build=/vagrant/codes/web_build
class_dir=$web_build/web_server/webapps/GCP6.1/WEB-INF/classes
lib_dir=/vagrant/codes/GCP6.1/WebRoot/WEB-INF/lib
find $src_dir -type f -name "*.java" -exec javac -cp "$lib_dir/*:$src_dir" -d $class_dir {} \;
rsync -auC --exclude='*.java' $src_dir/ $class_dir/
Take care there's no folder named "core" in $src_dir, or it will be excluded by the "-C" option of rsync command.
A Test Case
$ tree
.
├── classes
├── lib
│ ├── libadd.jar
│ └── libmul.jar
├── libadd
│ └── com
│ └── boco
│ └── gcp
│ └── add
│ ├── MyAdd.class
│ └── MyAdd.java
├── libmul
│ └── com
│ └── boco
│ └── gcp
│ └── mul
│ ├── MyMul.class
│ └── MyMul.java
└── main
└── com
└── boco
└── gcp
├── Test.java
└── util
└── MyUtil.java
17 directories, 8 files
$ find . -name '*.java' -exec cat {} \; -exec echo "--------" \;
package com.boco.gcp.util;
import com.boco.gcp.add.MyAdd;
import com.boco.gcp.mul.MyMul;
public class MyUtil {
public int newadd(int x, int y) {
MyAdd add = new MyAdd();
MyMul mul = new MyMul();
return add.myadd(3,5) + mul.mymul(3,5);
}
}
--------
package com.boco.gcp;
import com.boco.gcp.mul.MyMul;
import com.boco.gcp.add.MyAdd;
import com.boco.gcp.util.MyUtil;
public class Test {
public static void main(String[] args) {
MyMul mul = new MyMul();
MyAdd add = new MyAdd();
System.out.println(mul.mymul(3,5));
System.out.println(add.myadd(3,5));
MyUtil util = new MyUtil();
System.out.println(util.newadd(3,5));
}
}
--------
package com.boco.gcp.mul;
public class MyMul {
public int mymul(int x, int y) {
return 10*x*y;
}
public static void main(String[] args) {
MyMul mul = new MyMul();
System.out.println(mul.mymul(3,5));
}
}
--------
package com.boco.gcp.add;
public class MyAdd {
public int myadd(int x, int y){
return 10*x+y;
}
public static void main(String[] args) {
MyAdd add = new MyAdd();
System.out.println(add.myadd(3,5));
}
}
--------
$ find main -name '*.java' -exec javac -cp 'lib/*:main' {} -d classes \;
$ tree classes/
classes/
└── com
└── boco
└── gcp
├── Test.class
└── util
└── MyUtil.class
Compile Java Codes in Linux Shell instead of Ant Script的更多相关文章
- java代码运行linux shell操作
1.Java调用shell Java语言以其跨平台性和简易性而著称,在Java里面的lang包里(java.lang.Runtime)提供了一个允许Java程序与该程序所运行的环境交互的接口,这就是 ...
- Java 连接远程Linux 服务器执行 shell 脚本查看 CPU、内存、硬盘信息
pom.xml jar 包支持 <dependency> <groupId>com.jcraft</groupId> <artifactId>jsch& ...
- java使用Runtime.exec()运行windwos dos或linux shell命令
使用Runtime.exec()运行windwos dos或linux shell命令,按实际情况具体测试 实例代码: package com.bookoo.test.command; imp ...
- Java文件操作API功能与Windows DOS命令和Linux Shell 命令类比
Java文件操作API功能与Windows DOS命令和Linux Shell 命令类比: Unix/Linux (Bash) Windows(MS-DOS) Java 进入目录 cd cd - 创建 ...
- java远程调用linux的命令或者脚本
转载自:http://eksliang.iteye.com/blog/2105862 Java通过SSH2协议执行远程Shell脚本(ganymed-ssh2-build210.jar) 使用步骤如下 ...
- java classpath批量设置shell脚本
java classpath批量设置shell脚本 注意:linux bash jar文件之间的分隔符是':' export JAR_HOME=path to directory which ...
- linux shell 使用总结
为什么执行脚本要使用./ +脚本名来执行脚本理解:因为如果直接使用脚本名,那么linux 系统会去path 路径查找如去/bin usr/bin 等查找,这个时候会找不到这个脚本名字,就会报错.使用. ...
- paip.注册java程序为LINUX系统服务的总结。
paip.注册java程序为LINUX系统服务的总结. ////////////////实现开机启动. 标准方法是按照/etc/init.d/下面的文件,修改一下:然后chkconfig xxx on ...
- linux shell 流程控制
导读 和Java.PHP等语言不一样,linux shell有一套自己的流程控制语句,其中包括条件语句(if),循环语句(for,while),选择语句(case).下面我将通过例子介绍下,各个语句使 ...
随机推荐
- Docker安装单点RabbitMQ
环境准备 Centos 7.5 docker环境 安装步骤 拉取镜像 $ docker pull rabbitmq:management 说明: 获取rabbiymq镜像的时候要记得获取managem ...
- 在Xshell中文件内容显示乱码
1.修改系统语言 支持中文 echo $LANG 查看系统语言 默认 en_US.UFT_8 vim /etc/locale.conf 修改配置文件 将LANG的值改为 zh_CN.UT ...
- ESP32-使用ADC笔记
基于ESP-IDF4.1 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include "freertos/FreeRT ...
- kali2020安装中文界面
1.安装中文字体:apt-get install xfonts-intl-chinese ttf-wqy-microhei 2.设置系统语言:dpkg-reconfigure locales 3.选择 ...
- python 10篇 操作mysql
一.操作数据库 使用pip install pymysql,安装pymysql模块,使用此模块连接MySQL数据库并操作数据库. import pymysql host = 'ip地址' # 链接的主 ...
- shell脚本编写规范和相关变量类型
shell编程规范与变量 一.shell脚本概述 ① 什么是shell? Linux中有哪些shell? ② shell的作用 ③ 用户的登录shell ④ shell脚本 ...
- python 并行
网址:http://www.parallelpython.com/ 下载模块[根据使用环境选择相应的下载版本]下载pp-1.6.4.4 .zip,注意不要下载md5 解压缩上面下载的文件:pp-1.6 ...
- 交换机H3C S3100V2-52TP-WiNet
H3C S3100V2-52TP-WiNet参数 使用手册三层交换机 默认管理IP:192.168.0.234 将电脑IP设置为192.168.0.0这一组,网络连接交换机,默认用户名密码都为adm ...
- C语言:fopen函数
在C语言中,操作文件之前必须先打开文件:所谓"打开文件",就是让程序和文件建立连接的过程.打开文件之后,程序可以得到文件的相关信息,例如大小.类型.权限.创建者.更新时间等.在后续 ...
- DataFrame的创建
DataFrame的创建从Spark2.0以上版本开始,Spark使用全新的SparkSession接口替代Spark1.6中的SQLContext及HiveContext接口来实现其对数据加载.转换 ...