NeoCortex97
NeoCortex97
JCHJava Community | Help. Code. Learn.
Created by NeoCortex97 on 10/2/2024 in #java-help
Packaging maven submodules
My project has different components and everything is tied together with grpc, so everything is inside of one maven project to start with: My maven submodule structure looks like this:
root
+- interface
pom.xml
+- server
pom.xml
+- part_a
+- client_a
pom-xml
+- ui_a
pom.xml
pom.xml
+- part_b
+- client_b
pom-xml
+- ui_b
pom.xml
pom.xml
root
+- interface
pom.xml
+- server
pom.xml
+- part_a
+- client_a
pom-xml
+- ui_a
pom.xml
pom.xml
+- part_b
+- client_b
pom-xml
+- ui_b
pom.xml
pom.xml
And I would like my complete application part end up as a fat jar in the target folders of part _a and part_b respectively. How would you configure maven to do this? I tried a lot of configurations of the maven-jar-plugin and maven-shade-plugin .
8 replies
JCHJava Community | Help. Code. Learn.
Created by NeoCortex97 on 8/6/2024 in #java-help
Converting library to maven package
Hi, I need to write Software for a piece of Hardware that has an sdk that's not available as a maven package. I would like to supply that library internally as a maven package, so it can be used without messing with library path and other things. But I don't know enough to do that. I will write a wrapper for the sdk, that makes it more convenient and comfortable to use overall. So a would be developer should not be interacting with the sdk directly. And I will implement our internal coding guidelines on that wraooer. But I don't know how I could package the native libraries and supply the correct libraries for the target platform and dynamically add the correct set of libraries to the library path before using the sdk. Any leads or solutions?
9 replies
JCHJava Community | Help. Code. Learn.
Created by NeoCortex97 on 6/26/2024 in #java-help
Maven semantic versioning
Hi, I would like to implement the following semantic version ING scheme for my company in a maven parent or archetype. M.m.R.P-B M: Major Version m: Minor Version R: Revision (Sprint number) P: patch B: Build number The Build number should always be incrementing if the project is packaged. Please don't try to argue with me that this scheme is dumb, this was a requirement by our QA department which is not willing do deviate from their scheme of allways incrementing numbers. I don't work at a tech company and I don't make the rules. I'd rather have the build be dependent on the patch, and allways reset for a new patch, but that's not allowed. How would you implement something like this? I tried the release plugin for maven and the version plugin, but I was not too successful with any of them.
8 replies
JCHJava Community | Help. Code. Learn.
Created by NeoCortex97 on 5/25/2024 in #java-help
Maven multiple parents for project
Hi, I would like to share some code between my frontend and backend application and I would like to do that by having a maven Parent for the whole project with 3 submodules. I will call them: - root - whole project parent project - frontend - just frontend specific code - backend - spring boot project - common - shared code but I don't want to make root being a child of spring boot. backend has to be a child for spring boot, but it would have to be a child of root too. I dont know hot to say this better.
12 replies
JCHJava Community | Help. Code. Learn.
Created by NeoCortex97 on 5/18/2024 in #java-help
Loading Resources with absolute path from Classpath
I need to Load resources with absolute path from all modules that are present. Example: I have the following modules: * com.example.appmanager * com.example.demoapp * com.example.utilscreens And I want to load /com/example/appmanger/base.fxml as well as /com/example/demoapp/MainScreen.fxml from a class in com.example.appmanager. No matter What I try it does not find the resources. Here is my code for finding the resource:
for (Module mod : ModuleLayer.boot().modules())
if(mod.getName().startsWith(prefix)) {
log.debug(mod.getName());
try {
log.debug(String.valueOf(mod.getResourceAsStream(resource)));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
for (Module mod : ModuleLayer.boot().modules())
if(mod.getName().startsWith(prefix)) {
log.debug(mod.getName());
try {
log.debug(String.valueOf(mod.getResourceAsStream(resource)));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
For now it only prints the URL, but that would be sufficient for a demo. Any hints for a better way to do this, or hints what I am doing wrong or a solution would be greatly apreciated.
105 replies
JCHJava Community | Help. Code. Learn.
Created by NeoCortex97 on 3/1/2024 in #java-help
Spring Boot Mail not sending attachments
I am building a Mail notifiaction system, that should attach PDF reports that are stored in an S3 bucket. I followed the documentation, but the attachment is not displayed by Outlook. Here is my code for actually sending the mail:
@Observed(name = "mail.send", contextualName = "sending-templated-mail")
public void sendMailFromTemplate(MailInstance instance){
// Loading a template
try {
// Conditioning metadata
MimeMessage message = sender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
helper.setTo(instance.dest());
helper.setFrom(instance.src());
helper.setSubject(subject);
helper.addInline("logo", logoFile);
message.setContent(result, "text/html");
List<File> toClean = new ArrayList<>();
instance.attachments().forEach(item -> {
log.info(item);
try {
InputStream stream = fileService.download("test-results", item);
File f = new File(scratch, item);
FileUtils.copyToFile(stream, f);
FileSystemResource resource = new FileSystemResource(f);
helper.addAttachment(item.split("/")[1], resource);
toClean.add(f);
} catch (MessagingException e) {
throw new RuntimeException(e);
}
});
sender.send(message);
log.info("Cleaning cache directory");
toClean.forEach(File::delete);
} catch (MessagingException | TemplateException | IOException e) {
throw new RuntimeException(e);
}
}
@Observed(name = "mail.send", contextualName = "sending-templated-mail")
public void sendMailFromTemplate(MailInstance instance){
// Loading a template
try {
// Conditioning metadata
MimeMessage message = sender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
helper.setTo(instance.dest());
helper.setFrom(instance.src());
helper.setSubject(subject);
helper.addInline("logo", logoFile);
message.setContent(result, "text/html");
List<File> toClean = new ArrayList<>();
instance.attachments().forEach(item -> {
log.info(item);
try {
InputStream stream = fileService.download("test-results", item);
File f = new File(scratch, item);
FileUtils.copyToFile(stream, f);
FileSystemResource resource = new FileSystemResource(f);
helper.addAttachment(item.split("/")[1], resource);
toClean.add(f);
} catch (MessagingException e) {
throw new RuntimeException(e);
}
});
sender.send(message);
log.info("Cleaning cache directory");
toClean.forEach(File::delete);
} catch (MessagingException | TemplateException | IOException e) {
throw new RuntimeException(e);
}
}
I don't know if this is a thing with outlook, or with my code.
2 replies
JCHJava Community | Help. Code. Learn.
Created by NeoCortex97 on 2/16/2024 in #java-help
Spring boot jpa envers metadata
I need to store additional Metadata in my revision log. I had the choice to add the fields to the revision entity, but it looked unclean to me, because one logical operation could and should stretch multiple revisions and that meant redundant data.... The only thing missing is that I now need to provide envers with the Metadata entity this revision belongs to and filling Metadata.
5 replies
JCHJava Community | Help. Code. Learn.
Created by NeoCortex97 on 2/5/2024 in #java-help
Cannot find RElative resize on a previewous working project
I am getting thwe following error now that i am centrally loading my JavaFX Scenes by a custom class.
Caused by: java.lang.NoSuchMethodError: 'void com.sun.javafx.scene.NodeHelper.recalculateRelativeSizeProperties(javafx.scene.Node, javafx.scene.text.Font)'
at javafx.controls/javafx.scene.control.Labeled$6.set(Labeled.java:375)
at javafx.controls/javafx.scene.control.Labeled$6.set(Labeled.java:347)
at javafx.graphics/javafx.css.StyleableObjectProperty.applyStyle(StyleableObjectProperty.java:68)
at javafx.controls/javafx.scene.control.Labeled$6.applyStyle(Labeled.java:361)
at javafx.controls/javafx.scene.control.Labeled$6.applyStyle(Labeled.java:347)
at javafx.graphics/javafx.scene.CssStyleHelper.transitionToState(CssStyleHelper.java:787)
at javafx.graphics/javafx.scene.Node.doProcessCSS(Node.java:9647)
...
Caused by: java.lang.NoSuchMethodError: 'void com.sun.javafx.scene.NodeHelper.recalculateRelativeSizeProperties(javafx.scene.Node, javafx.scene.text.Font)'
at javafx.controls/javafx.scene.control.Labeled$6.set(Labeled.java:375)
at javafx.controls/javafx.scene.control.Labeled$6.set(Labeled.java:347)
at javafx.graphics/javafx.css.StyleableObjectProperty.applyStyle(StyleableObjectProperty.java:68)
at javafx.controls/javafx.scene.control.Labeled$6.applyStyle(Labeled.java:361)
at javafx.controls/javafx.scene.control.Labeled$6.applyStyle(Labeled.java:347)
at javafx.graphics/javafx.scene.CssStyleHelper.transitionToState(CssStyleHelper.java:787)
at javafx.graphics/javafx.scene.Node.doProcessCSS(Node.java:9647)
...
And i know that the code was working before i implemented a centralized scene manager. The manager works pretty well and still works on scenes that dont try to call this method....
36 replies
JCHJava Community | Help. Code. Learn.
Created by NeoCortex97 on 6/9/2023 in #java-help
Maven deploy to gitlab package repo
Hey, I setup a local gitlab server and I would like to publish my artifacts to the maven repo that is provided by gitea. I followed the steps to setup the credentials from the maven docs. And copied the example code. But the deployment fails every time I try. I can't show you the error at the moment, because I'm not at work today. But I can certainly replicate the setup locally and post that error. Could you recommend a good guide how to setup deployment in maven?
6 replies
JCHJava Community | Help. Code. Learn.
Created by NeoCortex97 on 6/8/2023 in #java-help
Generating normal and chainable Setters with Lombok
Hi, I am using Lombok to generate constructors, getters and Setters for my spring data model. I think I heard that I'd need to implement getters and Setters following the bean conventions for jpa to work. But I would like to use chainable Setters for the bussiness logic. Do you know of any way to do this. If there is no obvious way to do that, I would be willing to implement custom annotation processing to generate them myself.
17 replies
JCHJava Community | Help. Code. Learn.
Created by NeoCortex97 on 6/5/2023 in #java-help
Gradle PreferencesFX does something weird
I want to use PreferencesFX in a project with gradle. So I created a little demo application to test it. This is my whole controller to test PreferencesFX:
package com.example.uitests;

import com.dlsc.preferencesfx.PreferencesFx;
import com.dlsc.preferencesfx.model.Category;
import com.dlsc.preferencesfx.model.Group;
import com.dlsc.preferencesfx.model.Setting;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.fxml.FXML;
import javafx.scene.control.Label;

public class HelloController {
@FXML
private Label welcomeText;
private StringProperty test = new SimpleStringProperty();
private IntegerProperty test2 = new SimpleIntegerProperty();

@FXML
protected void onHelloButtonClick() {
welcomeText.setText("Welcome to JavaFX Application!");
PreferencesFx prefs = PreferencesFx.of(Preferences.class,
Category.of("Test",
Group.of("Test",
Setting.of("Test", test)),
Group.of("Test2",
Setting.of("Test2", test2))));
prefs.show(true);
}
}
package com.example.uitests;

import com.dlsc.preferencesfx.PreferencesFx;
import com.dlsc.preferencesfx.model.Category;
import com.dlsc.preferencesfx.model.Group;
import com.dlsc.preferencesfx.model.Setting;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.fxml.FXML;
import javafx.scene.control.Label;

public class HelloController {
@FXML
private Label welcomeText;
private StringProperty test = new SimpleStringProperty();
private IntegerProperty test2 = new SimpleIntegerProperty();

@FXML
protected void onHelloButtonClick() {
welcomeText.setText("Welcome to JavaFX Application!");
PreferencesFx prefs = PreferencesFx.of(Preferences.class,
Category.of("Test",
Group.of("Test",
Setting.of("Test", test)),
Group.of("Test2",
Setting.of("Test2", test2))));
prefs.show(true);
}
}
If I try to run it, I get the following error:
> Task :HelloApplication.main() FAILED
Error occurred during initialization of boot layer
java.lang.module.FindException: Module gson not found, required by com.dlsc.preferencesfx

Execution failed for task ':HelloApplication.main()'.
> Process 'command '/usr/lib/jvm/java-17-openjdk-amd64/bin/java'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Task :HelloApplication.main() FAILED
Error occurred during initialization of boot layer
java.lang.module.FindException: Module gson not found, required by com.dlsc.preferencesfx

Execution failed for task ':HelloApplication.main()'.
> Process 'command '/usr/lib/jvm/java-17-openjdk-amd64/bin/java'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
6 replies
JCHJava Community | Help. Code. Learn.
Created by NeoCortex97 on 6/5/2023 in #java-help
Copying resource file into directory before compile
I need to change resource files for different scenarios. Please don't ask me why, the explanation is quite lengthy if you want to understand it. The short explanation is legacy code and a really old library that is required in my domain. I need the files to be present, before any code generation or compilation is performed. These resources are referenced by some Library that performs checks and code generation during compile time. I can not dump the library and write a better one from scratch, since the old one needed to undergo a pretty expensive certification which I am not really comfortable to disclose here. Do you know an existing maven plugin, that can perform a cop operation besides maybe antrun? If there is not, I will write my own plugin and maintain it. It would be cheaper to do that, than to get certification for a new library.
.
├── pom.xml
├── src
│   └── main
│   ├── java
│   │   ├── com
│   │   │   ...
│   │   └── module-info.java
│   └── resources
│   ├── ci
│   │   └── foo.cnf.xmf
│   ├── com
│   │   ...
│   ├── foo.cnf.xml
│   ├── production
│   │   └── foo.cnf.xml
│   └── testing
│   └── foo.cnf.xml
...
.
├── pom.xml
├── src
│   └── main
│   ├── java
│   │   ├── com
│   │   │   ...
│   │   └── module-info.java
│   └── resources
│   ├── ci
│   │   └── foo.cnf.xmf
│   ├── com
│   │   ...
│   ├── foo.cnf.xml
│   ├── production
│   │   └── foo.cnf.xml
│   └── testing
│   └── foo.cnf.xml
...
This is an example of what my directory structure might look like. The one in the resources directory is supposed to be the destination. I want to do this inside of maven, so I could avoid writing special scripts and needing an explanation for every new developer how to set up the run configs in intellij correctly. If I would do that, someone would have to maintain it with changing versions of Intellij in the future and we all know that this will not happen.
15 replies
JCHJava Community | Help. Code. Learn.
Created by NeoCortex97 on 6/1/2023 in #java-help
Error when using CustomStage with java 17 and openjfx 17
when I try to run my project, I get the following error: Error occurred during initialization of boot layer java.lang.module.FindException: Module CustomStage not found, required by com.example.jfxmoderntest
Execution failed for task ':HelloApplication.main()'.
> Process 'command '/usr/lib/jvm/java-1.17.0-openjdk-amd64/bin/java'' finished with non-zero exit value 1
Execution failed for task ':HelloApplication.main()'.
> Process 'command '/usr/lib/jvm/java-1.17.0-openjdk-amd64/bin/java'' finished with non-zero exit value 1
What does this mean and how could I fix it? I am using gradle, so here is an except of my build.gradle:
dependencies {
implementation('lk.vivoxalabs.customstage:CustomStage:1.3.2')
implementation('org.controlsfx:controlsfx:11.1.2')
implementation('com.dlsc.formsfx:formsfx-core:11.6.0') {
exclude(group: 'org.openjfx')
}
implementation('net.synedra:validatorfx:0.4.0') {
exclude(group: 'org.openjfx')
}
implementation('org.kordamp.ikonli:ikonli-javafx:12.3.1')

testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
}
dependencies {
implementation('lk.vivoxalabs.customstage:CustomStage:1.3.2')
implementation('org.controlsfx:controlsfx:11.1.2')
implementation('com.dlsc.formsfx:formsfx-core:11.6.0') {
exclude(group: 'org.openjfx')
}
implementation('net.synedra:validatorfx:0.4.0') {
exclude(group: 'org.openjfx')
}
implementation('org.kordamp.ikonli:ikonli-javafx:12.3.1')

testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
}
9 replies
JCHJava Community | Help. Code. Learn.
Created by NeoCortex97 on 5/14/2023 in #java-help
Overlays for different maven Profiles
I want to have different configurations for different build types. I implemented my build types as maven profiles that mutually exclude each other with development as a default. My directory structure looks something like:
...
resources
development
...
testing
...
release
...
...
resources
development
...
testing
...
release
...
I tried to set the matching directory as the resource root. But that did not work at all... I was trying to find an example with the shade plugin, since it will be used anyways to build a fat jar. If you know of an example i would be glad. Nonetheless would I prefer to overlay the resource directory with the special build type directories. I am dumb in regards to maven, so I don't even know how to google for that. If there is nothing, I would be able to build my own plugin.
5 replies