Skip to content

Commit ddb569d

Browse files
committed
Add Java support
1 parent 4513386 commit ddb569d

File tree

24 files changed

+420
-1
lines changed

24 files changed

+420
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

compiled_starters/java/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
java_shell.jar
2+
target/*
3+
target/
4+
.idea/

compiled_starters/java/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/shell.png)
2+
3+
This is a starting point for Java solutions to the
4+
["Build Your Own Shell" Challenge](https://app.codecrafters.io/courses/shell/overview).
5+
6+
_Add a description of your course here_
7+
8+
**Note**: If you're viewing this repo on GitHub, head over to
9+
[codecrafters.io](https://codecrafters.io) to try the challenge.
10+
11+
# Passing the first stage
12+
13+
The entry point for your `shell` implementation is in `src/main/java/Main.java`.
14+
Study and uncomment the relevant code, and push your changes to pass the first
15+
stage:
16+
17+
```sh
18+
git add .
19+
git commit -m "pass 1st stage" # any msg
20+
git push origin master
21+
```
22+
23+
Time to move on to the next stage!
24+
25+
# Stage 2 & beyond
26+
27+
Note: This section is for stages 2 and beyond.
28+
29+
1. Ensure you have `java (21)` installed locally
30+
1. Run `./your_shell.sh` to run your program, which is implemented in
31+
`src/main/java/Main.java`.
32+
1. Commit your changes and run `git push origin master` to submit your solution
33+
to CodeCrafters. Test output will be streamed to your terminal.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Set this to true if you want debug logs.
2+
#
3+
# These can be VERY verbose, so we suggest turning them off
4+
# unless you really need them.
5+
debug: false
6+
7+
# Use this to change the Java version used to run your code
8+
# on Codecrafters.
9+
#
10+
# Available versions: java-21
11+
language_pack: java-21

compiled_starters/java/pom.xml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>io.codecrafters</groupId>
8+
<artifactId>build-your-own-shell</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<maven.compiler.source>21</maven.compiler.source>
13+
<maven.compiler.target>21</maven.compiler.target>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<java.version>21</java.version>
16+
</properties>
17+
18+
<build>
19+
<plugins>
20+
<plugin>
21+
<groupId>org.apache.maven.plugins</groupId>
22+
<artifactId>maven-assembly-plugin</artifactId>
23+
<configuration>
24+
<finalName>java_shell</finalName> <!-- Please do not change this final artifact name-->
25+
<descriptorRefs>
26+
<descriptorRef>jar-with-dependencies</descriptorRef>
27+
</descriptorRefs>
28+
<appendAssemblyId>false</appendAssemblyId>
29+
<archive>
30+
<manifest>
31+
<addClasspath>true</addClasspath>
32+
<!-- This is the main class of your program which will be executed-->
33+
<mainClass>Main</mainClass>
34+
</manifest>
35+
</archive>
36+
<outputDirectory>${dir}</outputDirectory>
37+
</configuration>
38+
39+
<executions>
40+
<execution>
41+
<id>make-assembly</id>
42+
<phase>package</phase>
43+
<goals>
44+
<goal>single</goal>
45+
</goals>
46+
</execution>
47+
</executions>
48+
</plugin>
49+
</plugins>
50+
</build>
51+
</project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Uncomment this block to pass the first stage
2+
// import java.util.Scanner;
3+
4+
public class Main {
5+
6+
public static void main(String[] args) throws Exception {
7+
// Uncomment this block to pass the first stage
8+
// Scanner sc = new Scanner(System.in);
9+
10+
// You can use print statements as follows for debugging, they'll be visible when running tests.
11+
System.out.println("Logs from your program will appear here!");
12+
13+
System.out.print("$ ");
14+
// Uncomment this block to pass the first stage
15+
// String input = sc.nextLine();
16+
}
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
#
3+
# DON'T EDIT THIS!
4+
#
5+
# CodeCrafters uses this file to test your code. Don't make any changes here!
6+
#
7+
# DON'T EDIT THIS!
8+
set -e
9+
mvn -B --quiet package -Ddir=/tmp/codecrafters-shell-target
10+
exec java -jar /tmp/codecrafters-shell-target/java_shell.jar "$@"

course-definition.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ languages:
1919
- slug: "go"
2020
- slug: "python"
2121
- slug: "rust"
22+
- slug: "java"
2223

2324
marketing:
2425
difficulty: medium

dockerfiles/java-21.Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM maven:3.9.5-eclipse-temurin-21-alpine
2+
3+
COPY pom.xml /app/pom.xml
4+
5+
WORKDIR /app
6+
7+
# Download the dependencies
8+
RUN mvn -B package -Ddir=/tmp/codecrafters-shell-target
9+
10+
# Cache Dependencies
11+
RUN mkdir -p /app-cached
12+
RUN mv /app/target /app-cached # Is this needed?
13+
14+
# Pre-compile steps
15+
RUN printf "cd \${CODECRAFTERS_SUBMISSION_DIR} && mvn -B package -Ddir=/tmp/codecrafters-shell-target && sed -i 's/^\(mvn .*\)/#\1/' ./your_shell.sh" > /codecrafters-precompile.sh
16+
RUN chmod +x /codecrafters-precompile.sh
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

0 commit comments

Comments
 (0)