When I was trying "I want to build Java Applet without IDE" written by ke9000, one project is fine, but in the school class When I switch the source code frequently like this, I rewrite the HTML file every time and create a Classes folder ... I realized that it was difficult to do it. Therefore, I will try to make it easy to operate, although it is limited to OS such as Linux and Mac. Of course, what I'm doing is too obvious and not helpful, but I'll write it as a memorandum. Basically, I will proceed on the assumption that I have read the above article, but I will write the code as appropriate. (** Note: The reason why I copy to the Classes folder every time is that I can't move the original source file from the src folder because I use NetBeans in class **)
This time, we will work in a folder called ~ / Java. Let's assume that you have a project folder in Java / and the source code in it.
applet.html
<html>
<head><title>Applet Test</title></head>
<body>
<applet code="CLASS_NAME.class" width="150" height="150">
</applet>
</body>
</html>
Save this as ** ~ / Java / applet.html **
applet.sh
#!/bin/sh
javac $1.java
#Of the name passed as an argument.Compile java file
if [ -e $1.html ]; then
:
else
cat <Java folder path>/applet.html | sed "s/CLASS_NAME/$1/" > $1.html
fi
#Based on the html file created earlier, "CLASS_Make a change of "NAME" to the file used at that time. If there is, I won't make it.
mkdir Classes 2>/dev/null
#Create if there is no Classes folder
cp *.class Classes
#Made by compiling.Copy class files to Classes/Overwrite copy
appletviewer $1.html
#Launch Applet
It was okay to branch with if for mkdir, but the error is simply "I can't make it because it already exists!", So it's okay if I don't display it. By the way, it is assumed that applet.html and applet.sh are in the same directory.
Write the shell script you just created in bashrc so that you can easily execute it in the .java folder.
.bashrc
alias applet='<applet.sh path>/applet.sh'
Go to the location of the source code (hoge.java) of the program that used the applet,
applet hoge(.I don't need java)
So, it will compile, move to the specified folder, and start up)
that's all.
~~ As I said in the original article, isn't JavaApplet deprecated? ~~
Recommended Posts