Ask coding questions

← Back to all posts
When I run my Java Swing program, it does not always recompile.
mrsawyer (1)

Unlike in a "regular" Java repl, in a Java Swing repl you see the java files and the class files. I made changes to a java file that had no effect when I ran the program (but should have). Then I deliberately put in a compiler error and it still ran. Then a deleted a class file and I got an "exit status 1" because it could not find the class whose class file deleted. Any ideas on how to force repl.it to recompile the code prior to running it? Thanks.

Comments
hotnewtop
Highwayman (1455)

Maybe, but first it’d probably help if we could see your repl, which seems to be private. I’d suggest manually compiling your program using a .replit file and see if that changes anything.

mrsawyer (1)

Thanks for the response. Ok, how do I manually compile it using a .replit file? (and I just changed it public if that helps).

Highwayman (1455)

@mrsawyer sorry for the late reply. The docs on how to configure the run button are here: https://docs.repl.it/repls/dot-replit

mrsawyer (1)

Thanks Highwayman, that fixed it.

KnutLei (0)

@Highwayman I had the same problem and found help here. Thanks.

BUT: It seems odd, that I have to write a .replit file for Java Swing project, while I don't have to do so in Java. What's the reason? It means, that I have to adjust the .replit file each time I add, rename or remove a class!?!?

Highwayman (1455)

@KnutLei well, you could always try and get clever...

.replit:

# javac Main.java Main1.java Main2.java Main3.java Main4.java Main5.java util.java plist.java -o Main
run="FILES="Main.java Main{1..5}.java {util,plist}.java" ; javac $FILES -o Main ; java Main"

Or even better: Use a makefile! probably best to just use a makefile:

.replit:

run="make"

Makefile:

# I don't remember how to use make but it's cool and you can probably make a small script that'll just figure out all the java files in your directory for you, like with a ls and then an xargs or whatever.