Git Hub Codespace setup
jdk version update
sdk install java 21.0.3-tem
If SDK Not available curl -s "https://get.sdkman.io" | bash source "$HOME/.sdkman/bin/sdkman-init.sh" sdk install java 21.0.3-tem
Install These Extensions Extension Pack for Java Spring Boot Extension Pack
Ctrl+Shift+P -> command Pallete Opening. search spring init...
creating maven project
Before you start, you need the Extension Pack for Java by Microsoft. This is a bundle that includes:
- Language Support for Java™ (by Red Hat)
- Debugger for Java
- Maven for Java (This is the one that does the heavy lifting)
- Open VS Code and press
Ctrl + Shift + P(to open the Command Palette). - Type "Java: Create Java Project" and select it.
- Choose "Maven" from the list of build tools.
- Select a "maven-archetype-quickstart".
- Tip: This is the most basic template for a console-based Java application.
- Select the version (usually
1.4or the latest available). - Input Group Id: Use something professional like
com.bank. - Input Artifact Id: Name your project (e.g.,
banking-system). - Choose a folder on your computer where the project will live.
Once you select the folder, a terminal will open at the bottom. Maven might ask you to confirm the properties:
- It will show the
groupId,artifactId, andversion. - Press
Enterto confirm or typeYif prompted.
VS Code will then generate the standard Maven structure for you:
src/main/java: Your source code.src/test/java: Where your unit tests go.pom.xml: Your configuration file where you will add your PostgreSQL and other dependencies.
- Adding Dependencies: To add the JDBC driver for Postgres, you don't need to download a
.jarmanually. Just open yourpom.xml, and inside the<dependencies>tag, add the Postgres dependency. VS Code will detect the change and ask to synchronize the project. - Running the App: You can just click the "Run" or "Debug" text that appears floating above your
public static void mainmethod.
This is a very common issue when using the default Maven template (archetype). It defaults to Java 7, but modern environments (like your workspace) require at least Java 8 or higher.
The fix is simple. You just need to tell Maven to use a newer version of Java in your pom.xml.
- Open your
pom.xmlfile. - Look for the
<properties>section. It usually looks like this:<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> </properties>
- Change the
1.7to1.8(or11or17if you prefer, but1.8is the standard for most learning projects).
Update it to look like this:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>- Save the
pom.xml. - Run the command again:
mvn clean install
Since you are using VS Code, it usually detects changes in the pom.xml and asks to synchronize. However, it is a great habit to run a manual build to ensure the dependency is actually downloaded and recognized by your local repository.
In your VS Code terminal, run:
mvn clean installclean: Removes thetargetfolder (old compiled files).install: Downloads the PostgreSQL driver from the internet and puts it in your local.m2folder.
If you see BUILD SUCCESS, your Java code is now officially "aware" of the PostgreSQL classes.