ubuntu下面的java一键运行脚本
程序员文章站
2022-03-04 08:53:26
...
java的运行分为编译+执行两部分.
怪麻烦的,所以写个脚本一键运行.如下:
--------------------------------------------------------------------------------------------------
java_compile.sh
#!/bin/bash
file_name="$1"
name=${file_name%.*}
echo file name is: $name
javac $1
java $name
chmod u+x java_compile.sh
--------------------------------------------------------------------------------------------------
.bashrc的配置
######################JAVA_HOME########################
export JAVA_HOME=~/Java/jdk1.8.0_131
export SPARK_HOME=~/bigdata/spark-2.3.1-bin-hadoop2.7
export CLASSPATH=.:${JAVA_HOME}/lib:${JAVA_HOME}/lib/*.jar:$SPARK_HOME/jars/*
export PATH=$PATH:${JAVA_HOME}/bin:${JAVA_HOME}/jre/bin
alias java=/home/appleyuchi/java_compile.sh
--------------------------------------------------------------------------------------------------
使用方法,任意文件夹下面建立文件helloworld.java
public class helloworld
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
保存并关闭.
当前路径下打开终端,输入java helloworld.java
运行结果如下:
file name is: helloworld
Hello World!