I am having some problems deploying my application in Wildfly 24.
I created a Module containing some jar's that aid my deployments executions. Some of those Jar's have annotations like #Entity and #WebService.
According with the Wildfly documentation, I created a global module in the standalone.xml like:
<global-modules>
<module name="server.defs" annotations="true" />
</global-modules>
Also, I have created (via maven) the jandex index for both the jar in the module and the jar deployed. On opening the jar's I can see the jandex.idx on the META-INF folder. To do this i used in the pom.xml the following:
<plugin>
<groupId>org.jboss.jandex</groupId>
<artifactId>jandex-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<id>make-index</id>
<goals>
<goal>jandex</goal>
</goals>
</execution>
</executions>
</plugin>
But when i start the server, its like the annotations are not parsed.
Hibernate can't find the class's with the #Entity annotations and the class's using the #WebService annotations in the modules are failing to deploy.
If I don't use the modules, everything is deployed correctly..
Anyone has any idea of whats the problem?
Thank you!
I left the project in standby for a while and now I rebooted it. Answering the original question, yes you can have annotated class's in the modules directories.
Just be sure every single dependency needed is included in the module.xml. You don't need any ' annotations="true" '.
Related
In Spring Boot, you can do the following:
src/main/resources/META-INF/spring.factories
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.admin.AConfiguration,\
org.springframework.boot.autoconfigure.admin.BConfiguration,\
org.springframework.boot.autoconfigure.admin.CConfiguration,\
org.springframework.boot.autoconfigure.admin.DConfiguration,\
org.springframework.boot.autoconfigure.admin.EConfiguration,\
org.springframework.boot.autoconfigure.admin.FConfiguration,\
Which is very nice. However after a year of development the list of auto configuration is now > 15 lines, which makes it hard to manage.
Would like to know if it is possible to separate the spring.factories into multiple files? Preferably would like to keep the whole project in one JAR.
Or maybe there is another ways to help organize the EnableAutoConfiguration that I am not aware of?
Thanks in advance!
While using spring-boot we use multiple "starters", each with an auto-configuration and spring.factories file.
So, one way could be to split your project into modules - one for each auto-configuration, define a dedicated spring.factories file in the module, and import all the modules as a runtime dependency in the main application module.
You can use maven or gradle to manage the multi-module project and the dependencies among them:
Gradle: https://guides.gradle.org/creating-multi-project-builds/
Maven: https://www.baeldung.com/maven-multi-module
Example:
root
moduleA
src/main/resources/META-INF/spring.factories
moduleB
src/main/resources/META-INF/spring.factories
and so on...
I have found a solution for this question.
Note: This exact solution assume that you only used EnableAutoConfiguration in your spring.factiores, it would crash if you use more than one type of config inside spring.factories.
One can do:
src/main/resources/META-INF/spring.factories
src/main/resources/META-INF/spring-2.factories
src/main/resources/META-INF/spring-3.factories
src/main/resources/META-INF/spring-4.factories
and merge this into one file.
Note, I am using Maven Antrun but I suspect Gradle would also have a similar feature.
In your pom.xml, add the following:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>default-ci</id>
<goals>
<goal>run</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<target>
<replace token='org.springframework.boot.autoconfigure.EnableAutoConfiguration=' value=','
dir="${project.build.directory}/classes/META-INF">
<include name="spring-*.factories"/>
</replace>
<concat destfile="${project.build.directory}/classes/META-INF/spring.factories" overwrite="yes" append="yes">
<fileset dir="${project.build.directory}/classes/META-INF" includes="spring-*.factories" />
</concat>
</target>
</configuration>
</execution>
</executions>
</plugin>
And in spring.factories is the normal config:
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.admin.AConfiguration,\
org.springframework.boot.autoconfigure.admin.BConfiguration
But in spring-2.factories and others, you start with ,\ instead of the default statement:
spring-2.factories:
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.admin.CConfiguration
spring-3.factories:
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.admin.DConfiguration
After all that, the outcome spring.factories in your output class directories will be a very nice:
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.admin.AConfiguration,\
org.springframework.boot.autoconfigure.admin.BConfiguration,\
org.springframework.boot.autoconfigure.admin.CConfiguration,\
org.springframework.boot.autoconfigure.admin.DConfiguration
Via this github project, I store Tomcat sessions in Redis:
https://github.com/chexagon/redis-session-manager
And in src/webapp/META-INF/context.xml file I added new commands:
<Manager className="com.crimsonhexagon.rsm.redisson.SingleServerSessionManager"
endpoint="redis://localhost:6379"
sessionKeyPrefix="_ib_"
saveOnChange="false"
forceSaveAfterRequest="false"
dirtyOnMutation="false"
ignorePattern=".*\\.(ico|png|gif|jpg|jpeg|swf|css|js)$"
maxSessionAttributeSize="-1"
maxSessionSize="-1"
allowOversizedSessions="false"
connectionPoolSize="100"
database="0"
timeout="60000"
pingTimeout="1000"
retryAttempts="20"
retryInterval="1000"
/>
If jar file is in Tomcat lib folder, then everything is fine. But in production if I add jar to lib folder it causes errors. Is there any other way for solving this problem? Can I change context.xml in such way that when I will deploy project, manager className will be able found relevant class?
P.S. There are some examples but I couldn't catch the sense:
Adding external resources to class-path in Tomcat 8
If someone can enlighten me, I will be grateful.
Thanks in advance
I could find solving. There is a plugin in maven for deploying war file. With this plugin it is possible to add files to war file. For example, I created folder which is named redis and add into it jar file. Then I added plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>redis</directory>
<targetPath>WEB-INF/lib</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
I have a Java web project that we deploy on the server of two different customers, 99% of the code is the same, right now I have two ApplicationBuilders, which is the class that contains the customization for each customer.
Anytime I want to deploy the new version I have to manually comment a line, build (with maven), uncomment that line, comment the other one and build again.
public class ApplicationBuilderFactory {
private static final IApplicationBuilder app;
static {
// app = new Customer1ApplicationBuilder()
app = new Customer2ApplicationBuilder();
}
}
public static IApplicationBuilder get() { return app; }
}
I want to avoid all this and the best thing would probably just create two different wars.
What's a good way to do this? I don't use (nor like) dependency injection frameworks and it seems overkill to add one just for a single class, but I may consider it.
One way to approach this is to use the Maven WAR Plugin Overlays feature.
Instead of trying to build multiple artifacts from one project (which can become unwieldy after a while), you create one base WAR project, and then a separate WAR project for each customer that only contains the components that need to be different.
Each customer specific WAR will be overlaid with the base WAR. This will make it easier to customise not only the ApplicationBuilderFactory but also specific web content and assets.
This also has the following benefits
customer specific features are guaranteed to be isolated from each other;
different customers can have their own release cycle and source control repository
it's easy to add subsequent customers
Create 2 different Maven Profiles, one for each customer, that copies a version of class ApplicationBuilderFactory to the right directory before compile stage.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>copy-files</id>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target name="copy files">
<copy file="${project.build.sourceDirectory}/pkg/ApplicationBuilderFactory.java.${extension}" tofile="${project.build.sourceDirectory}/pkg/ApplicationBuilderFactory.java" />
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>customer1</id>
<properties>
<extension>customer1</extension>
</properties>
</profile>
<profile>
<id>customer2i</id>
<properties>
<extension>customer2</extension>
</properties>
</profile>
Instead of having only one src/main/java/pkg/ApplicationBuilderFactory.java, we have:
src/main/java/pkg/ApplicationBuilderFactory.java.customer1
src/main/java/pkg/ApplicationBuilderFactory.java.customer2.
So before compiling java code, we copy one of these versions to the src/main/java/pkg/ApplicationBuilderFactory.java.
So generate 2 different .wars using 2 different profiles.
I have packaged a number of composite components in a JAR. However, when using them in another project (using Maven), Netbeans editor puts red error lines under lines which use the composite component, even though the project compiles and runs as expected.
The folder structure for the composite component JAR look like:
compositeComponent.jar
META-INF
faces-config.xml
highcharts-taglib.xml
MANIFEST.MF
web.xml
maven
// maven stuff.
resources
highcharts
Chart.xhtml
Series.xhtml
Tooltip.xml
nz
co
kevindoran
highcharts
example
NZPopulationTrend.class
The highcharts.taglib.xml looks like:
<facelet-taglib version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd">
<namespace>http://nz.co.kevindoran/highcharts-jsf</namespace>
<composite-library-name>highcharts</composite-library-name>
</facelet-taglib>
[Side note: The faces-config.xml and web.xml are present to allow the 'JAR' to be deployed as a WAR by changing the file extension to WAR (this is to done to run the examples).]
In my current project, I have specify a Maven dependency on the above project like so:
<dependency>
<groupId>nz.co.kevindoran</groupId>
<artifactId>jsf-menu</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
In a JSF page, I use on of the composite components like so:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:hc="http://nz.co.kevindoran/highcharts-jsf">
....
<hc:TimeChart title="Price Over Time" xLabel="Date" yLabel="Sold Price (NZD)">
<hc:TimeSeries name="Sold" series="#{cc.attrs.model.priceVsTimeChart.soldSeries}"/>
</hc:TimeChart>
....
</html>
Red error lines appear under all lines above, with message: "No library found for namespace http://nz.co.kevindoran/highcharts-jsf"
How do I get these error lines to be removed? I have seen many Netbeans bug reports for similar issues, but all seem resolved.
This error occurs on Netbeans 7.1, 7.2 and 7.3 (including 7.3.1).
I have absolutely the same problem. In my case it depends on the /src/main/java folder. If it's exist (only in the project and not even in the jar) the project which includes this library shows the "No library found for namespace... "
When i remove the "java" folder it works. But then my backing bean class is missed in the jar...
Tried with Netbeans 7.2 and 7.3, maven 2
Solution:
Generate a second project which contains the Java source files. (called: jsf-lib-java)
In jsf-lib project (your composite component project with xhtml) delete the "java" folder and all *.java sources.
add in the jsf-lib pom.xml following configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.mycompany.project</groupId>
<artifactId>jsf-lib-java</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>src/main/</outputDirectory>
<includes>**/*.class</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
That's it. This will generate a "good" jar file with the required *.class files. So it's possible to "trick" Netbeans.
Now i work with this solution. It's a hack but didn't found a better solution.
I have a maven plugin that should run in the compile phase, so in the project that consumes my plugin, I have to do something like this:
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>my-goal</goal>
</goals>
</execution>
</executions>
What I need is to by default attach my-goal to the compile phase if the user has included my plugin already (ideally the above part wouldn't be necessary, just the plugin declaration).
Is this possible?
Put an #phase annotation in your Mojo classdef annotations.
The doc says:
#phase <phaseName>
This annotation specifies the default phase for this goal. If you add an execution for this goal to a pom.xml and do not specify the phase, Maven will bind the goal to the phase specified in this annotation by default.
If this doesn't work, I guess a JIRA is warranted.
Create an instance of src\main\resources\META-INF\plexus\components.xml in your plugin.
In there create a LifeCycle mapping for the artifact types that your want your Mojo to support. Make sure that it lists all the phases and plugins you want to support. Probably best to copy from the one from maven-core.jar.
Then add your plugin in to the appropriate LifeCycle(s) at the phase at which you want them built.
Eg the consume-aar Mojo added into the compile phase of the aar lifecycle.
<!-- Android archive (aar) support -->
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>aar</role-hint>
<implementation>
org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping
</implementation>
<configuration>
<phases>
<generate-sources>
com.jayway.maven.plugins.android.generation2:android-maven-plugin:generate-sources
</generate-sources>
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
<compile>
com.jayway.maven.plugins.android.generation2:android-maven-plugin:consume-aar,
org.apache.maven.plugins:maven-compiler-plugin:compile
</compile>
This is possible, but it is an undocumented maven feature.
Use this components.xml:
<component-set>
<components>
<component>
<role>org.apache.maven.lifecycle.Lifecycle</role>
<implementation>org.apache.maven.lifecycle.Lifecycle</implementation>
<role-hint>myplugin</role-hint>
<configuration>
<id>accurest</id>
<phases>
<phase>my-plugin-not-used-phase</phase>
</phases>
<default-phases>
<compile>
my.package:my-plugin:${project.version}:my-goal
</compile>
</default-phases>
</configuration>
</component>
</components>
but your plugin need to be added with <extensions>true</extensions> to modify existing lifecycle.
More: How to bind plugin mojos (goals) to few phases of default lifecycle?
Real project: https://github.com/spring-cloud/spring-cloud-contract/blob/master/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/main/resources/META-INF/plexus/components.xml
You associate plugin to maven lifecyle goal. The plugin configuration should be declared in phase.
For example if you wan to run some plugin during build phase you'll need to do something like this :
<project>
...
...
<build>
<plugin>
**Configuration of plugin**
</plugin>
</build>
</project>
Please read carefully about maven lifecycles here (it is fundamental for understanding of maven):
http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
And then read about how to configure a plugin : http://maven.apache.org/guides/mini/guide-configuring-plugins.html
P.S. Getting into logic of maven is not easy at the beginning. But it is rewarding afterwards.