I want to use Java Applet easily on the command line without using an IDE

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 **)

1. About folder structure

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.

2. Prepare the HTML file


<head><title>Applet Test</title></head>

<applet code="CLASS_NAME.class" width="150" height="150">


Save this as ** ~ / Java / applet.html **

3. Write a shell script



javac $1.java
#Of the name passed as an argument.Compile java file
if [ -e $1.html ]; then
    cat <Java folder path>/applet.html |  sed "s/CLASS_NAME/$1/" > $1.html
#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.

4. Register with an alias

Write the shell script you just created in bashrc so that you can easily execute it in the .java folder.


alias applet='<applet.sh path>/applet.sh'

5. Try it out

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

I want to use Java Applet easily on the command line without using an IDE
I want to build Java Applet without using an IDE
I want to use screen sharing on the login screen on Ubuntu 18
I want to use the Java 8 DateTime API slowly (now)
I just want to write Java using Eclipse on my Mac
To use the "java" command line tool ... How to avoid popping up
I tried to display the calendar on the Eclipse console using Java.
Using JUnit from the command line on Ubuntu
I want to send an email in Java.
I want to use java8 forEach with index
Use your own docker-compose.yml on the command line
Compile and run Java on the command line
I want to play a GIF image on the Andorid app (Java, Kotlin)
I want you to use Scala as Better Java for the time being
[Java] I want to calculate the difference from the date
I want to use NetBeans on Mac → I can use it!
I want to use ES2015 in Java too! → (´ ・ ω ・ `)
I want to judge the range using the monthly degree
[Android Studio] I want to use Maven library on Android
I want to call the main method using reflection
I want to simplify the log output on Android
[Android Studio] I want to set restrictions on the values registered in EditText [Java]
I want to implement it additionally while using kotlin on a site running Java
[Beginner] I want to modify the migration file-How to use rollback-
(´-`) .. oO (I want to easily find the standard output "Hello".
Use JLine when you want to handle keystrokes on the console character by character in Java
I want to use the sanitize method other than View.
I want to put the JDK on my Mac PC
How to install JDK 8 on Windows without using the installer
I want to pass the startup command to postgres with docker-compose.
I want to simplify the conditional if-else statement in Java
I want to use swipeback on a screen that uses XLPagerTabStrip
I want to return to the previous screen with kotlin and java!
I want to add the disabled option to f.radio_button depending on the condition
[Java] I want to perform distinct with the key in the object
I want to use FormObject well
Use the iostat command on CentOS 8
I want to download a file on the Internet using Ruby and save it locally (with caution)
Instructions for installing and using the AWS command line (awscli) on CentOS
How to place geckodriver (Selenium WebDriver) on the path using Maven command
I want to display the number of orders for today using datetime.
I want to get the IP address when connecting to Wi-Fi in Java
I want to display an error message when registering in the database
I want to ForEach an array with a Lambda expression in Java
I want to get the field name of the [Java] field. (Old tale tone)
[Java Spring MVC] I want to use DI in my own class
[Swift] How to set an image in the background without using UIImageView.
I want to introduce the committee with Rails without getting too dirty
I want you to use Enum # name () for the Key of SharedPreference
[Java] How to use the File class
[Java] How to use the hasNext function
I want to make an ios.android app
Map without using an array in java
[Java] How to use the HashMap class
I want to use DBViewer with Eclipse 2018-12! !!
[Java] How to use the toString () method
Studying how to use the constructor (java)
[Processing × Java] How to use the loop
I want to install PHP 7.2 on Ubuntu 20.04.
[Processing × Java] How to use the class
Try to use docker command without sudo.