Skip to content
Sign UpLog In
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
9

How can you get rid of the main.java file and replace it with another file?

akschindler
akschindler

How can you get rid of the main.java file and replace it with another .java file?

3 years ago

Voters

Comments

TopNew
3
JaredCollacchi
JaredCollacchi

using the Console: rm Mian.java

2 years ago
3
JaredCollacchi
JaredCollacchi

After that you have to use the Console to Compile/Run your Program

  1. Type "dir" to list all files in the Directory/Folder

  2. Type "javac [File_Name].java" to compile to code into a usable .class file

  3. Type "java [File_name]" to run the .class file

  4. "clear" clear all from console (Optional)

2 years ago
1
RowanFromBJC
RowanFromBJC

In shell: rm main.java && printf "" > .replit
Create a new file, and in the .replit file, add run="SHELL CODE TO RUN NEW FILE"

2 years ago
1
Zavexeon
Zavexeon

You cannot delete main.java in repl.it, that will always be the file that is executed first.

What is your goal?

3 years ago
2
rdeardorff
rdeardorff

@Zavexeon
to be able to execute a stand alone source file without also executing what is inside main...main executes first and then the separate source file does not run. I would like to use this in my class but I cannot because of this limitation.

The only workaround I have found is to copy the source into Main.java and then give the class file the name Main. But that limits being able to give multiple assignments to students.

bottom line, i don't want Main to be executed first.

3 years ago
4
rdeardorff
rdeardorff

@rdeardorff
actually I don't want Main to exist. or we need to be able to rename it.

3 years ago
1
Zavexeon
Zavexeon

@rdeardorff
Uh... well you can't delete main, but I think if you create another file you can manually compile and execute it using the shell. Press F1 while in the repl, and in the search menu that appears type in "shell" and select "open shell". I can't guarantee this will work but it's might.

Another route might be to use a polygott repl and set up a makefile to compile and run whatever java file you want.

http://repl.it/languages/polygott

3 years ago
3
dublinmathking
dublinmathking

@Zavexeon
You can also in the public static void main(String[] args) method of Main.java call your target class's main method:

MyClass.main(args);

2 years ago
Load more