Ptkc is a library for configuration files. It was previously part of the PTK (Pixel Tool Kit) library, but has been separated into its own library for easier use and maintenance.
- Java 17 or higher
- Maven
To include ptkc in your project, add the following dependency and repository to your pom.xml
:
<dependency>
<groupId>com.pixelservices</groupId>
<artifactId>ptkc</artifactId>
<version>${ptkcversion}</version>
</dependency>
<repository>
<id>pixel-services-releases</id>
<name>Pixel Services</name>
<url>https://maven.pixel-services.com/releases</url>
</repository>
Here is an example of how to use ptkc to load a Yaml configuration file and get a value from it.
If (In this example) you would add a file named config.yml
to your compiled jar, ptkc would automatically load it, otherwise it would create one for you.
By running YamlConfig#save()
it will save the configuration to a file outside of the jar. That way a user can edit the configuration. If a external file is present, it will load that instead of the one in the jar.
import com.pixelservices.config.ConfigFactory;
import com.pixelservices.config.YamlConfig;
public class Example {
public static void main(String[] args) {
YamlConfig config = ConfigFactory.getYamlConfig("config.yml");
config.save();
}
}
By using YamlConfig#getString()
you can get a String value from the configuration file. Similarly, you can use YamlConfig#getInt()
to get an integer value.
To edit the configuration file, you can use YamlConfig#set(key, value)
to set a value.
import com.pixelservices.config.ConfigFactory;
import com.pixelservices.config.YamlConfig;
public class Example {
public static void main(String[] args) {
YamlConfig config = ConfigFactory.getYamlConfig("config.yml");
String value = config.getString("key");
String newValue = "new value";
config.set("key", newValue);
}
}
We welcome contributions! To contribute to ptkc:
- Fork the repository: ptkc on GitHub
- Create a feature branch:
git checkout -b feature-name
- Commit your changes:
git commit -m 'Add feature'
- Push to the branch:
git push origin feature-name
- Submit a pull request.