I have a monorepo with the following structure:
app
|lib
| -moduleA
| |-pom.xml
| -moduleB
| |-pom.xml
|services
| |-foo
| |-pom.xml
| |bar
| |-pom.xml
| |gamma
| |-pom.xml
My end goal here is to deploy the application's war files to aws via GitHub actions. I am able to deploy individual services whenever there are changes in them, with the command mvn clean install -Dmaven.clean.failOnError=false -f services/foo/pom.xml.
However, I am not sure how to update the services whenever a module it depends on is modified. For eg., foo and gamma depend on moduleA. Whenever moduleA is modified, I would like to build war files only for foo and gamma and exclude bar since there are no changes for it. Pretty new to java, any ideas how to achieve this? TIA
Was able to find a flag that updates the dependencies of the module
--also-make-dependents
Related
I have a Spring Boot + Spring Security application with React JS for client. I want to have a custom styled 404 error page in it without using Thymeleaf.
My Spring Boot version is 2.0.0.M2
The war file structure is
root-dir
|- WEB-INF
| |- lib
| |- classes
| | |- static
| | | |- * (react dist)
| | |- * (other files)
|- org
|- META-INF
My war file build process will be as follows.
Using Gradle npm plugin, build the ReactJS distribution
Gradle task that will copy the distribution to static directory in war
Build war finally
Please help me on this to solve.
No need to disable the white label page.
Just add a file named 404.html under the src/main/resources/public/error directory.
Baeldung.com indicates src/main/resources/public/errors, which does not work, at least with SpringBoot 2.1.x. Use the singular error and you will be good.
All of this work without any template engine in the project's dependencies.
I'm learning to use spring framework and I can't seem to find a tool similar to Django shell_plus. I'd like to be in a java repl in which I have access to all my classes, dependencies and etc. I've googled and found j-shell and spring-shell but spring-shell doesn't seem to satisfy my needs since I need to be able to instantiate and play around with my classes, so I went with j-shell. my only problem is I don't know how to let j-shell know where my classes are. I've tried
$ jshell --classpath "~/Desktop/path/to/project/"
my project directory being:
Project
|
+-- build.gradle
|
+-- build
| |
| +-- libs and etc...
+-- src
| |
| +-- main
| |
| +-- java
| |
| com
| |
| +-- MyClass.java
| |
| +-- MyOtherClass.java
|
+-- settings.gradle
+-- gradlew
+-- default.nix
but when in j-shell I don't have access to spring framework or my classes. I'm using emacs on nixos if that matters and nix for dev environment dependencies. appreciate any kind of help, thanks.
i've also tried setting the classpath to the jars located in ~/home/.gradle/
I expect to be in jshell repl with access to springframework classes and ones i've coded myself.
There are a few ways you could set the class path for a jshell session.
On startup, before you enter the REPL:
$jshell --class-path <your_classpath>
After you're already in a running REPL session:
jshell>/env -class-path <your_classpath>
Notice the difference between --class-path and -class-path? That's not a typo.
The old-fashioned way. Set a $CLASSPATH environment variable before you start jshell:
$export CLASSPATH=<your_classpath>
$jshell
There is actually a fourth way which makes the class path persistent between jshell sessions so you don't have to set it every time. It involves creating a .jsh startup file, and setting and saving it. From within a jshell session, see /help to find out more.
I made a Gradle plugin to run a jshell console with all the libraries of your project in the classpath: jshell-plugin , once configured in your build setup, you only need to run:
$ gradle --console plain jshell
Also the README instructions have a special section to setup it in a Spring Boot project and be able to access to the business objects (the beans in the Spring context: #spring-boot-applications:
jshell> var myUserService = ctx.App.getBean(MyUserService.class)
jshell> ctx.App.ppjson(myUserService.getByUsername("admin"))
{
"name" : "Jhon",
"lastName" : "Due",
"username" : "admin",
"age" : null
}
If you are not using Gradle and you have an old Spring Boot 1.x project, you can use another project I made that does not work with modern Spring Boot applications, but at least you don't need Gradle or the jshell from a JDK9+ distrubution to play with your code and the spring's beans: spring-ctx-groovy
I want to exclude a specific file from the base jar while running my project (which will use the base jar as dependency)
Base project structure looks like:-
baselib
|
|----src
| |
| |--some packages
| |
| |--resources
| | -- somefile.xml
|
|---target
Another project called "mycustomproject" will have "baselib" as dependency jar in pom.xml
My question i,s how to debug/run (Debug As/Run As-> Spring Boot App) the "mycustomproject" by excluding "somefile.xml" alone. I cannot remove this file in "baselib" since some one is using it.
Could someone share some inputs here?
I am working on a project that needs to be refactored in order to achieve decoupled modules.
I need to us an Adapter to decide which module to route to depending on some config.
+===========+
| Front-end |
+===========+
| |
+==================+ +==================+
| RESTful Service1 | | RESTful Service2 |
+==================+ +==================+
| |
+=========================+ +=========+
| Adapter | --- | Config |
+=========================+ +=========+
| | |
+=========+ +=========+ +=========+
| Module1 | | Module2 | | Module3 |
+=========+ +=========+ +=========+
I have a Java application, and want to package the modules in JARS using Maven.
RESTful Service1 will either talk to Module1 or Module2 while RESTful Service2 will always talk to Module3. I need to establish which is the nest way to package these modules.
RESTful Service1 will be in it's own Jar while Module1 and Module2 will have their own Jars too.
Question
Seeing that RESTful Service2 will always talk toModule3 only, should they be in the same Jar? Or should I separate them into two seperate Jars too?
Thanks
Because RS2 when deployed always needs to work with M3, putting them in the same jar offers one benefit: we won’t forget M3 when deploying RS2. But the downside is that it is difficult to reuse and deploy M3 to another system which does not require RS2.
I think the benefit above is little. Often, when deploying a system you should have a document or checklist. Even if some component was forgotten, chance is that you could detect and fix it quickly.
So the better option is to seperate RS2 and M3 into two jars.
I'm currently working on changing building process of legacy project. Right now it is built by a custom-made solution and our aim is to adjust it to a standard one - maven.
This is a standalone application and current output of a build is a directory with following structure:
OUR_APPLICATION
|
|_bin
| |_start.sh
| |_stop.sh
|
|_etc
| |_app.properties
|
|_jar
| |_app_classes1.jar
| |_app_classes2.jar
|
|_lib
|_third_party_library.jar
I am wondering what's the best way to achieve similar output with maven and still follow best practises (or at least break them as little as possible).
I'm leaning towards creation of multi-module project (separate modules for Java code, configuration files and shell scripts) and then using maven-assembly-plugin for combining it all together, but I'm not entirely sure how (if at all) it can be properly done.
Still I'm not sure whether its the best fit for me and I will be very grateful for any feedback.
You are on the right way (imo): Maven is a good tool for producing deployable artifacts. And the maven-assembly-plugin fits the needs that you described. It could produce a ZIP file containing the application structure you described.
The default artifact type that Maven produces is simply a JAR. This is ok for libraries. The application structure that you described seems to have three of them: app_classe1.jar, app_classes2.jar, and third_party_library.jar (I know, there could be more of them).
The Maven setup that I would suggest (and keep in mind: other ways exist): Create a multi-module project, which has modules for each application JAR and one module for assembling them. The parent project then simply builds them all. Like this:
ParentProject
|
|-- pom.xml (the parent one, that describes all modules)
|
|-- Module1 (producing app_classes1.jar)
| |
| |-- pom.xml
| |-- src/...
|
|-- Module2 (producing app_classes2.jar)
| |
| |-- pom.xml
| |-- src/...
|
|-- AssemblyModule (the one that produces a ZIP, for example)
|
|-- pom.xml (with type POM because it does not produce a JAR)
The assembly module should not have the default artifact type (JAR), but should be set to type POM. The pom.xml of that assembly module then configures the maven-assembly-plugin to create a ZIP file. The content of this ZIP file is highly configurable. Additionally, this plugin attaches the result artifact (the ZIP) to the build, so that it will be uploaded to a repository, if that is also configured.