This guide will help you set up your first tinystruct application and understand the basic workflow.
- Java Development Kit (JDK) 8 or higher
- Maven (for dependency management)
- A text editor or IDE (IntelliJ IDEA, Eclipse, VS Code, etc.)
Add the tinystruct dependency to your project's pom.xml
file:
<dependency>
<groupId>org.tinystruct</groupId>
<artifactId>tinystruct</artifactId>
<version>1.6.4</version>
<classifier>jar-with-dependencies</classifier>
</dependency>
Alternatively, you can download the JAR file directly from the Maven Repository and add it to your project's classpath.
Create a new Java class that extends AbstractApplication
:
package com.example;
import org.tinystruct.AbstractApplication;
import org.tinystruct.system.annotation.Action;
public class HelloWorldApp extends AbstractApplication {
@Override
public void init() {
// Initialization code
}
@Override
public String version() {
return "1.0.0";
}
@Action("hello")
public String hello() {
return "Hello, World!";
}
@Action("hello")
public String hello(String name) {
return "Hello, " + name + "!";
}
}
Create a config.properties
file in your project's resources directory:
# Application settings
application.name=HelloWorldApp
application.mode=development
# Server settings
server.port=8080
server.host=localhost
# Default settings
default.file.encoding=UTF-8
default.home.page=hello/World
default.reload.mode=true
default.date.format=yyyy-MM-dd HH:mm:ss
You can run your application from the command line using the tinystruct dispatcher:
# Display version
bin/dispatcher --version
# Run the hello action
bin/dispatcher hello --import com.example.HelloWorldApp
# Run with a parameter
bin/dispatcher hello/John --import com.example.HelloWorldApp
To run your application as a web server:
# Start the server with Netty
bin/dispatcher start --import org.tinystruct.system.NettyHttpServer --import com.example.HelloWorldApp
Then access your application at:
A typical tinystruct project structure looks like this:
my-app/
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── example/
│ │ │ ├── HelloWorldApp.java
│ │ │ └── ...
│ │ └── resources/
│ │ └── config.properties
│ └── test/
│ └── java/
│ └── com/
│ └── example/
│ └── HelloWorldAppTest.java
├── bin/
│ └── dispatcher
└── pom.xml
- Learn about Core Concepts
- Explore Web Applications
- Check out CLI Applications
- Understand Configuration
- Dive into Database Integration