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.
Related
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.
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/
I am stuck in Keycloak authentication of multi tenancy.
I have configured PathBasedKeycloakConfigResolver in my package: com.demo.util.
The context param has been set on web.xml
<context-param>
<param-name>keycloak.config.resolver</param-name>
<param-value>com.demo.util.PathBasedKeycloakConfigResolver</param-value>
</context-param>
I deployed the application on Tomcat. I have registered the context.xml in meta-inf with the required adapter.
Tomcat lib directory has all the required keycloak jar files.
But PathBasedKeycloakConfigResolver never gets called on any request to the url. PathBasedKeycloakConfigResolver should get called on any call to the url. The only time it calls if I remove the Maven dependency from the deployment assemply of Eclipse. But this cannot be the way to achieve this.
Sample of pathresolver:
public class PathBasedKeycloakConfigResolver implements KeycloakConfigResolver {
private final Map<String, KeycloakDeployment> cache = new ConcurrentHashMap<String, KeycloakDeployment>();
public KeycloakDeployment resolve(HttpFacade.Request request) {
System.out.println("**********I am called***************");
}}
pom.xml
<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">
<version>1.0.0.Final</version>
<modelVersion>4.0.0</modelVersion>
<groupId>org.keycloak.example.demo</groupId>
<artifactId>customer-portal-example</artifactId>
<packaging>war</packaging>
<!-- <name>Customer Portal - Secured via Valve</name> -->
<description />
<name>talent-biz-layer</name>
<dependencies>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-core</artifactId>
<version>1.4.0.Final</version>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-adapter-core</artifactId>
<version>1.4.0.Final</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/java/main</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
So you have the keycloak jar files in the tomcat lib directory and your war file? That will cause a conflict because your code will have its own version of the KeycloakConfigResolver interface (from your war file) which is not the same as the version used by keycloak (that comes from the tomcat lib directory). So your class is not implementing the keycloak version of the interface and not called because of that.
Solution: Use <scope>provided</scope> for all the jars that are in tomcat lib directory; this way you will have the classes for compilation, but the jars will not be added to your war file. Then there will be only the version in the tomcat lib directory and it will work.
I created an empty web project using Eclipse Mars and Maven 3.3.3. For now, this project only contains the pom.xml:
<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.example.project</groupId>
<artifactId>web-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
<build>
<plugins>
<!-- <plugin> -->
<!-- <groupId>org.apache.maven.plugins</groupId> -->
<!-- <artifactId>maven-war-plugin</artifactId> -->
<!-- <version>2.6</version> -->
<!-- <configuration> -->
<!-- <failOnMissingWebXml>false</failOnMissingWebXml> -->
<!-- </configuration> -->
<!-- </plugin> -->
</plugins>
</build>
</project>
Now Eclipse complains about a missing web.xml file. From the documentation of the maven-war-plugin one can set the user property failOnMissingWebXml, so there is no need to further configure this plugin. This works using Maven from the command line, the project is build successfully. But Eclipse still complains about the missing web.xml.
Does anybody know how to get rid of this Maven configuration error in Eclipse by just using this user property?
Update: I have another development environment using Eclipse Luna SR1 and Maven 3.2.5 where it does not complain about the missing web.xml in a newly created web project. So I wonder if this error is somehow suppressed by the m2e plugin.
Installing wtp-m2e 1.2.1 from http://download.eclipse.org/m2e-wtp/snapshots/mars/ fixes this issue for me.
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!