Ask coding questions

← Back to all posts
Jar files
zimtech0

Is it possible to include jar files in project classpath directory? Have a class project I would like to import along with classes contained in jar files.

Let me know thanks.

Voters
MtNetworkJPMt
michael_remington
WilliamJeggo
Bobster_61
noam2092005
DavidShen2
JohnAstill
jmalarcon
JohnSchlamann
zimtech0
Comments
hotnewtop
BrianWillem

Jar files can be uploaded to your project the same as other files. I put my jar files into a "jars" folder that I create in my repl.

From that point, you can compile and run your code from the command line:
javac -classpath .:./jars/ -d . Main.java
java -classpath .:./jars/
Main

If you want to configure the "Run" action, you can define a .replit file in your project and add the following line.
run = "export CLASSPATH=\".:./jars/*\"; javac -d . Main.java; java Main"

Configure these commands to match your environment, class names, etc.

tbaier

@BrianWillem Thank you so much for this, it was very helpful!

FaisalSarnap

@BrianWillem
Hi there. Apologies as I am still new to REPL as well as Java. I have a .jar file from the school that deals with a window pop up and I want to use it for my assignment. How do I add that into my repl project? Again, sorry, novice here. Thanks much!!

MOHAMEDSulai

how to add jar file in java?