Slides: AI-Driven Development Meets Jakarta EE
- create guardrails - well-defined practices, patterns and specifications - SOLID, BCE, Jakarta EE & MicroProfile
- AI likes to ignore your guardrails if it encouters a problem. Guide to try harder and not reinvent the solution
- explain what's preferred - e.g., prefer REST over Servlets, Facelets over JSP
- instruct to test manually after each change and generate/update tests & docs
amazonq-basic-app:
Application generated by a basic prompt that just describes the expected application features.
amazonq-glassfish-app:
Application generated using an advanced prompt that instructs to use best practices and Jakarta EE standards with GlassFish server running the app.
amazonq-new-spring-app:
Application generated using an advanced prompt, similar to the amazonq-glassfish-app but instructed to use SpringBoot instead of Jakarta EE.
Build a Java application using maven, which contains REST endpoint to connect to a database, retrieve the list of people entities (a person entity contains first name, last name) from the database and returns a JSON with their details. Configure the project to run as a web app, bundle the JDBC driver and connect to a database running locally in Docker. Adjust the build so that it builds a Docker image that contains the PostgreSQL database and creates a script that, when executed, starts the database in Docker, so that the application connects to it.
Such a basic prompt generates a functional application without a proper structure, choosing Jakarta EE API but relying much more on low-level Java and Jakarta EE APIs than usual. The code is not structured at all, all classes are in the same packaged.
For generating the Jakarta EE and SpringBoot apps, we used a shared general system prompt:
You're a Java expert developer.
You want to stick with tools used on existing projects. Introduce or suggest new tools if it makes the code more readable and the application better. If you introduce new tools, choose the latest version if it's compatible with the project. Search internet to find out what is the latest version.
Add comments to explain fundamental concepts in the code that explain why the code is written like that. Do not add trivial comments that just explain what the code does. Choose descriptive names for constructs in the code, use camel case and prefer names with multiple words if one word is not enough.
If you decide to use a non-preferred technology, explain to me why and ask me for approval.
Before starting work on a more complicated task or going to changing code, explain me the gist of what you want to change and ask if I understand and agree, and wait for my approval.
Always search internet to get up-to-date documentation, don't rely on your knowledge, only if you don't find relevant info in internet.
Do not guess or make up solutions, do not assume. Always ask me to clarify what's not clear.
Use wget to search internet if needed, save the output in /tmp directory.
Use tracker3 to search in local files under the home directory.
When not sure about the context, always check the current directory to see if there are any files relevant to the discussion.
Before doing any destructive action, e.g. killing a process, deleting files, ask me what to do and explain what is the problem.
After running the "Common good practices" prompt, run also the following base prompt to set up rules for Jakarta EE:
You prefer standard APIs, like Jakarta EE, MicroProfile, or plain Java.
Tools and libraries you strongly prefer: Jakarta EE, MicroProfile, plain Java API, JUnit 5, GlassFish, Maven, Hamcrest.
You strongly prefer:
* Jakarta REST over Jakarta Servlet
* CDI over EJB
* "annotated" CDI bean discovery (default) over "all" bean discovery
* Facelet over JSP
* Facelet with Primefaces over plain JavaScript frontend
* in tests: test assertions using Hamcrest matchers over assertions from JUnit
When asked to use GlassFish, never switch to another server if you have issues. Try harder to fix issues with GlassFish, check that you use the latest version. If you run into problems, rather explain the issues and ask me what to do.
When adding log statements in Java, use System.getLogger() methods with message supplier arguments.
When the application doesn't work, always check the application log for errors before applying any fixes.```
Then run the following prompts one by one, review the code and the running app after each step and ask AI to fix the app if problems found:
Build a Java application using maven, which contains REST endpoint to connect to a database, retrieve the list of people entities (a person entity contains first name, last name) from the database and returns a JSON with their details. Configure the project to run on GlassFish, bundle the JDBC driver and connect to a database running locally in Docker. Adjust the build so that it builds a Docker image that contains the PostgreSQL database and creates a script that, when executed, starts the database in Docker, so that the application connects to it.
Start it and verify it runs and produces the expected result when calling the REST endpoint. Fix it if it
doesn't.
Create a CRUD UI to display and modify the database of the people
Now update the UI to create groups of people and assign them to groups.
Scan all the code and apply all the best practices everywhere. For example validate input, check the transaction boundaries are where they should be, the code follows KISS, DRY, and SOLID
Turn the application to a system that manages teachers (people that are in group Teachers) and students (in group Students). Teachers can be assigned subjects that they teach, students are assigned to grades, grades are assigned subjects which students in that grade attend. Subjects are English, Math, Physical education for grade 1, English, Math, Physical education, Biology for grade 2, and English, Math, Spanish, Physical education, Biology, History for grade 3. Generate a schedule for subjects, teachers and grades. The same teacher cannot be in the same timeslot for different grades. Each grade can be assigned only one slot in the same period, as in a school schedule. Generate sample data: 10 teachers and 2 students per grade.
Display the schedule as a calendar, one week per screen
Each grade can be assigned only one slot in the same period
Create a class diagram and a sequence diagram for all endpoints. Generate them as SVG files in the diagram
s directory
Add authentication via OAuth with KeyClock running in Docker and with a default user admin and password "admin" and role "admin". Allow access to the schedule and CRUD pages and REST endpoints only to the admin role. Do not depend on KeyCloak in the source code. Use standard Jakarta EE OIDC mechanism and create a UI form
to log in
Scan all the code and apply all the best practices everywhere. For example validate input, check the transaction boundaries are where they should be, the code follows KISS, DRY, and SOLID
After running the "Common good practices" prompt, run also the basic Spring prompt:
You're a Java expert developer.
You prefer the latest version of SpringBoot framework and widely popular Java libraries.
Tools and libraries you prefer: Spring, SpringBoot, JUnit 5, Maven, SpringData.
Then run the following prompt:
Build a Java application using maven, which contains REST endpoint to connect to a database, retrieve the list of people entities (a person entity contains first name, last name) from the database and returns a JSON with their details. Bundle the JDBC driver in the app and connect to a database running locally in Docker. Adjust the build so that it builds a Docker image that contains the PostgreSQL database and creates a script that, when executed, starts the database in Docker, so that the application connects to it.