Learn to Code via Tutorials on Repl.it!

← Back to all posts
Configuring the RUN button (Java and Python Examples)
MrMazzone (8)

This tutorial will help you configure the RUN button in your repl.it project. Specifically, this example shows Python and Java files, but the information can be used to configure the RUN button for other projects.

The .replit file

To configure what the RUN button does in your project, you need to add a .replit file to your project.

Read more about the .replit file here: https://docs.repl.it/repls/dot-replit

In the .replit file you can define run as a string holding a shell command. Whatever shell command run is set to will execute when the RUN button is clicked for the project.

The easiest way to manage complex/multistep commands when the RUN button is clicked is to create a shell script (.sh). The .replit file's run can be set to execute the script by setting it to "bash filename.sh"

Example .replit file

run = "bash run_button.sh"

Java Code

For a Java project you need to compile the project using the javac command. You can either identify a .java file to compile or use *.java to compile all Java files in the folder. Then you can execute the Java class you want by using the java command followed by the class name.

javac *.java
java HelloWorld

More info here if you want to learn the basics of javac: https://www.dummies.com/programming/java/how-to-use-the-javac-command/

Python Code

For a Python project, you need to use the python or python3 command to execute a python file. Simple type the file name after the python command.

python example.py

More info here if you want to learn the basics of python command line: https://docs.python.org/3/using/cmdline.html


See example repl.it project below which runs a Java and Python run when the RUN button is clicked.

Notice how my example project is actually a Lua project and we are running Python and Java code. For the most part, when you configure the RUN button this way, the project type doesn't matter.

However, if you are creating a graphics or web project, they MUST be set to a graphics project (Python Tkinter, Java Swing, Python Turtle, etc.) or web project (HTML, CSS, JS).

Let me know if you have any questions! I will try to help!


Teachers: When using GitHub classroom, include the .replit file and the shell script in your repo. Teach students how to edit the files if they need to reconfigure the RUN button. Most situations they will not need to change it.

Commentshotnewtop
Highwayman (1358)

An extremely important tutorial.

goalkenhighligh (3)

Your share is the great knowledge I have gathered, you are an important person I admire, thank you https://happywheels8.com