Learn deeply about the Java build mechanism, learn build tools, and build a lightweight and simple learning environment without Eclipse. Target audience: People who understand Java but are not good at environment construction and deployment, and people who want to mention because their workplace uses Ant. By the way, this is me. My environment: macOS Assumption: The path to the Java VM is in place and the javac command works.
You can download it at Ant Official. Download the latest in zip format from here.
You can leave it as it is, but you can change it to a shorter name because it will be described in the environment variable later. It doesn't matter where you put it, but I put it in my home directory. I chose apache-ant here.
mv apache-ant ~/
cd
vim .bash_profile
Will open the path setting file, so (type the CD command with no arguments to go to the HOME directory)
ANT_HOME=~/apache-ant/bin
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/library/java/JavaVirtualMachines/jdk-12.0.1.jdk/contents/home/bin:$ANT_HOME
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
Add a path like the one above. ANT_HOME=~apache-ant/bin :$ANT_HOME Has just been added. Please note that other commands are different depending on the person, so if you copy and paste this whole, other commands may be broken.
ant --version
If there is a response, the installation is successful.
Directory structure
Put the build artifact in bin and the source code in src. ・ ・ Describe that in build.xml.
build.xml
<?xml version="1.0" encoding="UTF-8" ?>
<project name="HelloAnt" default="default" basedir=".">
<target name="default">
<javac srcdir="./src/" destdir="./bin/"/>
</target>
</project>
xml version = "1.0" encoding = "UTF-8"?> Is magic. Maybe if you don't write this, the characters will be garbled. Until you get used to it
I think it's like an HTML DOCTYPE declaration that looks good every time.
I think that it is one eclipse project by wrapping \
Main.java
class Main{
public static void main(String args[]){
System.out.println("hello ant");
}
}
Place it in the src directory and you're ready to go.
Just go to the directory where build.xml is and type the command below.
ant
BUILD SUCCESSFUL Is displayed, it is successful. You should have Main.class in your bin directory.
Recommended Posts