Trouble with deploying ear-file in Payara 5, that contains ejb-module - java

I'm trying to deploy ear file, that contains ejb module in dependecies in Payara 5.184 and getting error:
11.02.2019 13:57:15.938 | [payara-executor-service-scheduled-task] | ERROR | Exception while deploying the app [my-ear-SNAPSHOT]
11.02.2019 13:57:15.945 | [payara-executor-service-scheduled-task] | ERROR | Exception during lifecycle processing
java.lang.IllegalArgumentException: Invalid ejb jar [lib/my-ejb.jar]: it contains zero ejb.
Note:
1. A valid ejb jar requires at least one session, entity (1.x/2.x style),
or message-driven bean.
2. EJB3+ entity beans (#Entity) are POJOs and please package them as library jar.
3. If the jar file contains valid EJBs which are annotated with EJB component
level annotations (#Stateless, #Stateful, #MessageDriven, #Singleton),
please check server.log to see whether the annotations were processed properly.
With payara 4.1, this error does not occur. What should I do to fix the deployment error?
There is short version of my pom file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>my</groupId>
<artifactId>my-ears</artifactId>
<version>SNAPSHOT</version>
</parent>
<artifactId>my-ear</artifactId>
<packaging>ear</packaging>
<dependencies>
<dependency>
<groupId>my</groupId>
<artifactId>my-ejb</artifactId>
<version>${project.version}</version>
<type>ejb</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<version>6</version>
<generateApplicationXml>true</generateApplicationXml>
<skinnyWars>true</skinnyWars>
<defaultJavaBundleDir>lib/</defaultJavaBundleDir>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<filtering>true</filtering>
<modules>
<ejbModule>
<groupId>my</groupId>
<artifactId>my-ejb</artifactId>
<bundleDir>/lib</bundleDir>
</ejbModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
</project>

The problem was in domain.xml. I just copy it from payara 4.1 config folder and it was the wrong decision. The correct approach is this: take the original file and consistently make changes to it. Unfortunately, there is one more problem with EJB, but all the errors described above are gone.

Related

Springboot: application.properties path motification not taken into account

I'm creating a war file from a simple Spring boot (1.x) project, and I would like to modify the Context path.
For that purpose, I have an application.properties file that looks like this:
server.contextPath=/newpath
The project structure is the following:
.
src
main
...
resources
application.properties
The pom.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.api</groupId>
<artifactId>example</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Test project</name>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>1.5.9.RELEASE</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>example</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
When I perform a mvn package, I get a WAR file with the application.properties file located in /WEB-INF/classes, same content as the one I wrote. However, when deploying the war to Tomcat, I cannot access my API thru:
localhost:8080/newpath/example/some_controller
I can only query it via:
localhost:8080/example/some_controller
Am I missing something?
The server.context-path property only affects an embedded container. When deployed to an external container the context path is determined differently.
In the case of Tomcat, you could copy your application to the webapps directory as a file named newpath.war. It should then be available at localhost:8080/newpath/example/some_controller.
Please make sure you converted spring boot executable jar project into war file , there are three steps to convert to war file. Please follow steps given in this url -
https://www.mkyong.com/spring-boot/spring-boot-deploy-war-file-to-tomcat/

"Could not find or load main class" when running a jar file from a msf4j project

I'm working on a Java project which uses the msf4j library. In IntelliJ IDEA I'm able to run the project, everything works as expected. However, If I build a jar file from this project (aplying the first part of this answer), the jar file cannot run (using java -jar my_jar.jar). It says:
Error: Could not find or load main class Main
I've cleaned the project several times, restarted everything, even tried to use older versions of the msf4j, nothing has helped.
If I replace the msf4j with something else (e.g. javalin), the built jar file is runnable, the problem goes away.
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.group.id</groupId>
<artifactId>my_artifact</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.wso2.msf4j</groupId>
<artifactId>msf4j-core</artifactId>
<version>2.5.2</version>
</dependency>
</dependencies>
<properties>
<microservice.mainClass>src.main.java.Main</microservice.mainClass>
</properties>
</project>
MANIFEST.MF:
Manifest-Version: 1.0
Main-Class: Main
I think the problem is somewhere in the msf4j artifacts. Any idea how to fix this problem?
from the top of my head I thing you need to set in maven a project parent and remove the dependency.
<parent>
<groupId>org.wso2.msf4j</groupId>
<artifactId>msf4j-service</artifactId>
<version>2.5.2</version>
</parent>
HTH,
Gal

can we add ejb dependency into war or is it a bad practice

I am having a multimodule maven project:
Having three modules jar, war and ejb
I need to add ejb dependency in my war to access ejb bean so i created one ear and added them in it but still war cant find the ejb bean classes.here is the pom file of ear.Can anybody help me in this.And plz tell me can i add my ejb dependency directly in war or in parent pom coz i have read somewhere that its bad practice to add ejb dependencies directly.
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
ecommunicate.trutheq.ussdproject
pom.parent
1.0
Ussd.Project.EAR
ear
<dependencies>
<dependency>
<groupId>ecommunicate.trutheq.ussdproject</groupId>
<artifactId>Ussd.Project.Login</artifactId>
<version>1.0</version>
<type>war</type>
</dependency>
<dependency>
<groupId>ecommunicate.trutheq.ussdproject</groupId>
<artifactId>Ussd.Project.Ejb</artifactId>
<version>1.0</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>ecommunicate.trutheq.ussdproject</groupId>
<artifactId>Common.Utilities</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<earSourceDirectory>EarContent</earSourceDirectory>
<version>6</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<modules>
<webModule>
<groupId>ecommunicate.trutheq.ussdproject</groupId>
<artifactId>Ussd.Project.Login</artifactId>
</webModule>
<ejbModule>
<groupId>ecommunicate.trutheq.ussdproject</groupId>
<artifactId>Ussd.Project.Ejb</artifactId>
<bundleFileName>Ussd.Project.Ejb-1.0-jar-with-dependencies.jar</bundleFileName>
</ejbModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
The dependency in your .war module may look like the following. I am not sure why it could be considered as a bad practice and I can not think of the other way to make your ejb module accessible in your war module. Probably the author's idea was about adding ejb .jar in war's lib folder directly instead of keeping it in the .ear's lib folder. The link to the resource where you read it could help to clarify the idea
<dependency>
<groupId>ecommunicate.trutheq.ussdproject</groupId>
<artifactId>Ussd.Project.Ejb</artifactId>
<version>1.0</version>
<type>ejb-client</type>
<scope>provided</scope>
</dependency>
You can have any number of ejb jar dependencies in war module and its not a bad practice for sure.
But you should mark that dependency as "provided" in scope part in pom.xml, since its already available at the top level of that EAR.
EAR
|
|-lib/someutil.jar
|-EJB.jar
|-my-web.war
| |-WEB_INF/lib
| |-coolutil.jar
|-EJB2.jar
Here, my-web.war can dependent on EJB.jar (with provided scope).

Maven ear project with ejb and war modules

im working on a web application with maven and Jboss 7 wich conatins 3 modules ejb ear and war so the war will have the ejb as dependancy and the ejb will be in the same time a module of the ear so when i do this i get the same ejb twice this tree
ear
...Mywar
........Myejb
...Myejb
is this structure is correct or i should change another
the pom.xml for the war :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>tn.war.ep</groupId>
<artifactId>businessModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
.....
<dependency>
<groupId>tn.linckia.epgp</groupId>
<artifactId>ejbModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>ejb</type>
</dependency>
</dependencies>
</project>
the pom.xml for the ear :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>tn.war.ep</groupId>
<artifactId>earModule</artifactId>
<version>0.0.1</version>
<packaging>ear</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.6</version>
<configuration>
<modules>
<webModule>
<groupId>tn.war.ep</groupId>
<artifactId>businessModule</artifactId>
<bundleFileName>businessModule.war</bundleFileName>
<contextRoot>/businessModule</contextRoot>
</webModule>
<ejbModule>
<groupId>tn.war.ep</groupId>
<artifactId>ejbModule</artifactId>
<bundleFileName>ejbModule.jar</bundleFileName>
</ejbModule>
</modules>
<displayName>Security</displayName>
</configuration>
</plugin>
</plugins>
<finalName>AuthModule</finalName>
</build>
<dependencies>
<dependency>
<groupId>tn.war.ep</groupId>
<artifactId>businessModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>tn.war.ep</groupId>
<artifactId>ejbModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>ejb</type>
</dependency>
</dependencies>
</project>
Right way to configure EAR Module is to have the EJB jar dependency with "provided" scope in WAR module and having EJB jar directly under EAR like the below:
EAR
|
|-lib/someutil.jar
|-EJB.jar
|-my-web.war
| |-WEB_INF/lib
| |-coolutil.jar
|-EJB2.jar
But the my-web.war can dependent on the any EJB.jar, but its resolved in runtime by container. So, mark that ejb dependency as "provided" (by container) in WAR's pom.xml.
Option : #1
Yon don't even need a ear.
You can just put all your EJBs as jars inside the war.
Just add the EJB projects as dependencies in your War project.
Option : #2
If you still want EAR. All EJB projects output should be jars. And web project output should be war. And at last these EJB jars and web war would be placed in one EAR. This is a old fashion way, to keep it simple you could follow the method which I explained above in Option #1.
I had this issue and changing the ejb packaging tag from ejb to jar in the ejb modules pom.xml fixed the issue. No idea why!

Configuring WebApp With context.xml For Use Tomcat

I am using Maven 3 to build my project. I have a web application that I want to define the custom root. According to the Tomcat 6 Documentation it says:
The locations for Context Descriptors are:
1. $CATALINA_BASE/conf/[enginename]/[hostname]/context.xml
2. $CATALINA_BASE/webapps/[webappname]/META-INF/context.xml
Files in (1) are named [webappname].xml but files in (2) are named context.xml.
If a Context Descriptor is not provided for a Context, Tomcat configures the Context using default values.
I want to use a custom root that I define. How can this be achived because when I define the custom context.xml file, the path is not being seen in Tomcat. According to the above, it mentions if a Context Descriptor is not provided for a Context, Tomcat configures the Context using default values. I have already defined my Context Descriptor as seen below in context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/data1"/>
When I deploy deploy.war, into Tomcat I cannot access /data1 does not work. However, /data works. When the war file is deployed, it has META-INF with the context.xml located.
My POM file:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.data</groupId>
<artifactId>Java-WebApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Java-Web Application</name>
<!-- Shared version number properties-->
<properties>
<org.springframework.version>3.0.6.RELEASE</org.springframework.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0</version>
<configuration>
<webResources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
<finalName>data</finalName>
</build>
<parent>
<groupId>com.data</groupId>
<artifactId>Java-Parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
</project>
I have looked into the following website but don't seem to help:
Define Servlet Context in WAR-File
Looking at your pom, the name of the war file should be "webchannel".
You don't have to add a context.xml. Just let the url be determined by war file name, and any mappings you have created in project.

Categories

Resources