Console issue with replit

Does anyone know how to type in the console on replit? part of my project requires making a new file and then code. Once all of that is done, my prof tells us to “Press the run button, then enter java Exercise 1 in the console”. When i get to this part, the run feature only lasts 5 seconds (even if im fast enough to type out java Exercise 1 nothing happens.) please help.

1 Like

Hey @Dylan223!

You can use a prybar template (a Repl template) or you can type it in the shell. I hope this helps!

@SalladShooter I’m still kind of new to coding and my prof isnt the best, what do you mean i can use a repl template? also i tried tying java Exercise1 Java Exercise1 and even javaExercise1 into the shell. The console runs then nothing prints.

java Exercise1 will attempt to execute Exercise1.class, java Exercise1.java executes the source file Exercise1.java (has limitations). Use the shell for this.
javac Exercise1.java will compile it into Exercise1.class
If it is executing but your Exercise1.javawas blank it will be a no-op.

2 Likes

I see you made another topic that I presume contains the repl you are using. Simply execute with java Exercise1 then in the initial directory of the shell.

1 Like

Can you explain it a bit further? My prof is telling us to use the main.java (replits default repl when creating a js repl) then create a another file Exercise1.java. do i need to copy the code to the main.java file? If not how would i go about using the shell or console (this is my first time doing something like this)

Im still lost, can you explain it simpler? Sorry this is my first time doing something like this and my prof wont tell me how to get the print statement to work

Hello @Dylan223!

Instead of pressing the Run button, run javac path/to/filename.java && java filename in the shell.

2 Likes

I have to be missing something then, is there anything i have to do in the main.java file? like write a code that calls on the files? because thats my only other idea. nothing ive tried so far has worked. im new to this and was basically thrown head first in with no coding knowledge.

Could you provide a screenshot of your issue?




Could it be a no-op?

Hello @Dylan223!

Replit is automatically running the entrypoint “Main.java”, which is empty. You can change this by pressing the … on the Files sidebar, and press Show hidden Files. Open the .replit file, and change the entrypoint to “src/main/java/Exercise.java”.

I did that and tried running it again. Still not printing.



Even tried using the javac line

Try running kill 1 in the shell.

1 Like

Still nothing, could this just be an issue with replit or my laptop? (I have tried on different computers as well)


Interesting, try copy-pasting all the files to a new Java template.

okay give me a second to set up everything again

So new repl copied everything over, still only printed the main.js (hello world). Went into hidden files changed the entry to your suggestion. Tried all the statements in the shell that you suggested and only the main.js file is printing not the Exercise1 file

I have tested this and it works!
Please change your .replit file to:

compile = "javac -classpath .:target/dependency/* -d . $(find . -type f -name 'Exercise1.java')"
run = "java -classpath .:target/dependency/* Exercise1"
entrypoint = "src/main/java/Exercise.java"
hidden = ["**/*.class"]

[packager]
language = "java"

[packager.features]
packageSearch = true

[languages.java]
pattern = "**/*.java"

[languages.java.languageServer]
start = "jdt-language-server"

[unitTest]
language = "java"

[nix]
channel = "stable-22_11"

[debugger]
support = true

[debugger.compile]
command = "javac -classpath .:/run_dir/junit-4.12.jar:target/dependency/* -g -d . $(find . -type f -name '*.java')"

[debugger.interactive]
transport = "localhost:0"
connectTimeout = 60
startCommand = "java-debug"

[debugger.interactive.initializeMessage]
command = "initialize"
type = "request"

[debugger.interactive.initializeMessage.arguments]
adapterID = "cppdbg"
clientID = "replit"
clientName = "replit.com"
columnsStartAt1 = true
linesStartAt1 = true
locale = "en-us"
pathFormat = "path"
supportsInvalidatedEvent = true
supportsProgressReporting = true
supportsRunInTerminalRequest = true
supportsVariablePaging = true
supportsVariableType = true

[debugger.interactive.launchMessage]
command = "launch"
type = "request"

[debugger.interactive.launchMessage.arguments]
classPaths = ["."]
mainClass = "Main"

[deployment]
build = ["javac", "-classpath", ".:target/dependency/*", "-d", ".", "$(find . -type f -name '*.java')"]
run = ["java", "-classpath", ".:target/dependency/*", "Main"]
deploymentTarget = "cloudrun"
1 Like

okay i deleted everything in the .replit file and pasted what you sent, what command did you put into the shell to make it print? or could you send a screenshot of what you did? i’m so close to just taking a 0 because of this