Learn how to solve CodeCrafters challenges in Java
java
& mvn
installed. Our test runners use Java 21 (as of November 2023).
The script for your challenge (like ./your_bittorrent.sh
) will automatically compile your code using mvn
before executing it. It’ll
look something like this:
mvn
command will only be run once and then commented out. This ensures that each test only runs the java -jar ...
line.
src/main/java
directory.src/main/java/Main.java
contains the main
function, which is what the test runner executes.src/main/java
. The test runner will include them when compiling your code.
For example, if you added a file at src/main/java/Foo.java
, you could use it like so:
src/main/java
are in the default
package. If you want to extract files into a different package,
you’ll need to add a package
declaration to the top of the file and change its location. Here’s what that’d look like:
Let’s say you wanted to extract Foo.java
into the com.example
package. Store Foo.java
at src/main/java/com/example/Foo.java
and add the following lines:
pom.xml
file.
For example, to add the gson library, add the following to the <dependencies>
section in your pom.xml
: