Aze
Aze
Explore posts from servers
JCHJava Community | Help. Code. Learn.
Created by Aze on 11/1/2024 in #java-help
Gradle, Ebean: Service loader didn't find a SpiContainerFactory?
Hey, I'm having a problem with Ebean at the moment and hope someone here is able to help. It's the first time I'm using Gradle and the first time I'm using Ebean in private, so sorry if there's any obvious mistakes. This is the config I had using the "Getting Started" documentation:
plugins {
id("io.ebean") version "15.8.0"
}

dependencies {
implementation("com.mysql:mysql-connector-j:9.1.0")
implementation("io.ebean:ebean:15.8.0")
implementation("io.ebean:ebean-querybean:15.8.0")
annotationProcessor("io.ebean:querybean-generator:15.8.0")
}
plugins {
id("io.ebean") version "15.8.0"
}

dependencies {
implementation("com.mysql:mysql-connector-j:9.1.0")
implementation("io.ebean:ebean:15.8.0")
implementation("io.ebean:ebean-querybean:15.8.0")
annotationProcessor("io.ebean:querybean-generator:15.8.0")
}
Then I got an error message stating I should use driver specific packages (since Ebean 13+), which wasn't documented for gradle, so I checked out the Maven page and came up with this:
plugins {
id("io.ebean") version "15.8.0"
}

dependencies {
implementation("com.mysql:mysql-connector-j:9.1.0")
implementation("io.ebean:ebean-api:15.8.0") // fuer io.ebean.service.SpiContainer(Factory)
implementation("io.ebean:ebean-platform-mysql:15.8.0")
implementation("io.ebean:ebean-querybean:15.8.0")
annotationProcessor("io.ebean:querybean-generator:15.8.0")
}
plugins {
id("io.ebean") version "15.8.0"
}

dependencies {
implementation("com.mysql:mysql-connector-j:9.1.0")
implementation("io.ebean:ebean-api:15.8.0") // fuer io.ebean.service.SpiContainer(Factory)
implementation("io.ebean:ebean-platform-mysql:15.8.0")
implementation("io.ebean:ebean-querybean:15.8.0")
annotationProcessor("io.ebean:querybean-generator:15.8.0")
}
Now I'm getting an error about SpiContainerFactory not being found, even though the class is part of my jar. DatabaseProvider: https://paste.helpch.at/igogeyiraf.java Error: https://paste.helpch.at/dihajofopi.rb (also without shading)
13 replies
DDeno
Created by Aze on 9/29/2024 in #help
Missing express types
No description
6 replies
JCHJava Community | Help. Code. Learn.
Created by Aze on 5/3/2024 in #java-help
Annotations - interface as attribute type
Hey, I haven't found any useful resources on this. Maybe I'm using the wrong keywords, so I figured I should ask here: Why do annotations not allow interfaces as attribute types?
public interface MyInterface {
String upper();
}

public @interface MyAnnotation {
MyInterface value(); // Invalid type 'MyInterface' for annotation member
}
public interface MyInterface {
String upper();
}

public @interface MyAnnotation {
MyInterface value(); // Invalid type 'MyInterface' for annotation member
}
For some more context: I actually want to pass an enum, but use an interface to define a standard method (implementation can vary). This is just an example:
public enum MyEnum implements MyInterface {
1("One"),
2("Two");

private String string;

public MyEnum(String string) {
this.string = string;
}

@Override
public String upper() {
return string.toUpperCase();
}
}

@MyAnnotation(MyEnum.1)
public class MyClass {
// ... could then get the value and use `MyInterface#upper`
}
public enum MyEnum implements MyInterface {
1("One"),
2("Two");

private String string;

public MyEnum(String string) {
this.string = string;
}

@Override
public String upper() {
return string.toUpperCase();
}
}

@MyAnnotation(MyEnum.1)
public class MyClass {
// ... could then get the value and use `MyInterface#upper`
}
13 replies
JCHJava Community | Help. Code. Learn.
Created by Aze on 1/30/2024 in #java-help
Supplier alternative
Hey! I have some optional dependencies in my pom.xml (scope: provided). Now for each dependency I have a Hook class, which I would like to create an object of if the dependency is found. The following has bee confirmed to work:
public void register() {
if (isEnabled("MyDependency")) {
MyDependencyHook hook = new MyDependencyHook();
hookManager.setMyDependencyHook(hook);
}
}
public void register() {
if (isEnabled("MyDependency")) {
MyDependencyHook hook = new MyDependencyHook();
hookManager.setMyDependencyHook(hook);
}
}
While this works, it comes at the cost of having a bunch of code when handling multiple dependencies. So what I came up with instead is:
public void register() {
enable("MyDependency", MyDependencyHook::new, hookManager::setMyDependencyHook);
}

private <T> void enable(String name, Supplier<T> supplier, Consumer<T> consumer) {
if (!isEnabled(name)) return;

T instance = supplier.get();
consumer.accept(instance);
}
public void register() {
enable("MyDependency", MyDependencyHook::new, hookManager::setMyDependencyHook);
}

private <T> void enable(String name, Supplier<T> supplier, Consumer<T> consumer) {
if (!isEnabled(name)) return;

T instance = supplier.get();
consumer.accept(instance);
}
This cleans up my code base quite a bit, however, this will cause a java.lang.NoClassDefFoundError, which I believe is caused by the static reference of the hook? Can someone help me figure out an alternative? Any help is greatly appreciated^^
8 replies
JCHJava Community | Help. Code. Learn.
Created by Aze on 10/17/2022 in #java-help
Nitrite Database
I need help with Nitrite I followed these docs on how to open the database and how to open collections: https://www.dizitart.org/nitrite-database/#create-open-database https://www.dizitart.org/nitrite-database/#create-open-collections but no matter what I do, once I call the database or collection all I get is null. The error: https://pastebin.com/MxPemz0i My code: https://pastebin.com/Sy0SVqnh (the startDatabase() method is being called on start)
12 replies
JCHJava Community | Help. Code. Learn.
Created by Aze on 10/5/2022 in #java-help
need help with BigDecimal rounding
Hey, I'm trying to round a BigDecimal, but it doesn't seem to be working? I'm not sure if I'm doing it wrong or not.
BigDecimal sum = new BigDecimal("4.36");
BigDecimal coin = new BigDecimal("2.00");
BigDecimal amount = sum.divide(coin, RoundingMode.DOWN);
System.out.println(amount);
BigDecimal sum = new BigDecimal("4.36");
BigDecimal coin = new BigDecimal("2.00");
BigDecimal amount = sum.divide(coin, RoundingMode.DOWN);
System.out.println(amount);
judging by the docs https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/math/RoundingMode.html#DOWN I was expecting the amount to be 2, but instead it's 2.18
4 replies