How to deploy ApplicationLifecycleListener - deployment

I created an ApplicationListener extends ApplicationLifecycleListener in a java project, packaged as a jar file, create ear file contains this jar file, try to deploy it in the weblogic server with the "install" button in weblogic admin console(screenshot), I got error. If I pack it as a war file, create a ear file contains this war file, with the same approach I can deploy it with no error, but it does not being called.
I have searched on the internet for a while, a lot of people was talking about adding this listener to a weblogic-application.xml, I do not have this file in my project, I tried to find this in the weblogic server folders also can not locate it, I am new to weblogic, no idea how should I make a ApplicationLifecycleListener work.
Where should I find this weblogic-application.xml file? Or where do I need to create this file? Do I have to create a J2EE or EJB project? Or a java project can do this.
If possible please give me some detailed steps about deploying an ApplicationLifecycleListener. (I am using Jdeveloper)
First what project I should be using to write this listener class, and after coding, how to I register it, what is the best way and how should I deploy it.

In a typical maven EAR project, you'd put it in /myapp-ear/src/main/application/META-INF/, and it would look a bit like this:
<weblogic-application>
<listener>
<listener-class>com.myapp.SomethingSomethingServiceListener</listener-class>
<listener-uri>myapp-lib.jar</listener-uri>
</listener>
<!-- add whatever other things you'd normally put into weblogic-application-->
</weblogic-application>
Then /myapp-lib/src/main/java would have your listener code.
I like to put this code inside /myapp-ear/pom.xml but that's up to you:
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir>
<modules>
<jarModule>
<groupId>com.myapp</groupId>
<artifactId>myapp-lib</artifactId>
<bundleDir>/</bundleDir>
</jarModule>
</modules>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries><!-- weblogic really wants to know this for hot deploys -->
<Weblogic-Application-Version>${project.version}</Weblogic-Application-Version>
</manifestEntries>
</archive>
<fileNameMapping>no-version</fileNameMapping>
</configuration>
</plugin>
</plugins>
</build>

Related

Eclipse deploying unfiltered .WAR-Archive on Tomcat

i have the following problem: I want to use maven profiles and the maven-war-plugin for filtering my webapplication, so that it's just one click to deploy it either on the live- or on the development server.
When i build the .WAR-archive via Eclipse (Maven-Plugin) and then manually deploy it on the tomcat-server via the tomcat-manager-interface, my application works as expected. (all variables are replaced correctly inside the generated .WAR-archive)
But when i want to run the application using Eclipse's "Run on Server", an exception occurs:
[..] nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.security.web.authentication.logout.LogoutFilter]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: ${security.casEntryPoint.logoutSuccessUrl} isn't a valid redirect URL
This is the configuration of the maven profiles in my pom.xml:
<profiles>
<profile>
<id>prod</id>
<build>
<filters>
<filter>src/main/filters/dfnaaiAgreement-prod.properties</filter>
</filters>
</build>
</profile>
<profile>
<id>devLocal</id>
<build>
<filters>
<filter>src/main/filters/dfnaaiAgreement-devLocal.properties</filter>
</filters>
</build>
</profile>
This is an example entry for the *.properties file:
security.casEntryPoint.logoutSuccessUrl = https://example_entry/please_logmeout
This is one entry in the settings.xml that should be replaced by the value in the *.properties file:
<security:logout logout-url="/logout" logout-success-url="${security.casEntryPoint.logoutSuccessUrl}" />
and this is the configuration for the maven plugin (in the pom.xml), that is used for filtering the configuration files:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<warName>dfnaaiAgreement</warName>
<webResources>
<resource>
<directory>${basedir}/src/main/webapp</directory>
<filtering>true</filtering>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
</webResources>
</configuration>
This is my maven build configuration:
Maven-Build configuration (Sorry, not enough reputation to post images directly)
It seems like eclipse's "run on server" deploys the unfiltered application on the tomcat-server.
What am i doing wrong?
Update:
I followed this Link Run Maven webapp on server from Eclipse with properties injection from profile, but i'am still receiving the same Exception.
Here's the adjustment of my project's configuration: Active Maven Profiles
Update: Eclipse (Luna) deploys the webapplication to workspace/.metadata/.plugins/.org.eclipse.wst.server.core/tmp0/wtpwebapps/applicationName. The settings.xml that's deployed there still contains the unfiltered variables, whereas the generated .WAR-Archive (that is located at workspace/applicationName/target) has the correctly filtered settings.xml. How is this possible?
Thanks for your help!
Although it's not an optimal solution i found a workaround to fix my problem. Therefor i adjusted the project's deployment assembly settings in the way that the WEB-INF-Folder of the target-Folder will be taken for deployment.
You can do this by rightclicking your project and choose "Properties". Here's a screenshot of how i adjusted the settings:
Web_Deployment_Assembly.PNG

Dynamic Web Module 3.0 -- 3.1

I have a mavenized codebased configured Spring 3.2.4 web app.
When I build the app with Maven/pom.xml first I got an error that web.xml is missing.
first I tried to create an empty web.xml. this was the moment when The project facets changed (and I don't know why). It switched from dynamic Web Module 3.0 to 3.1 and this is irreversible.
How can I change it again into Dynamic Web Modules 3.0???
Additionally I can't remove the JAX-RS. Trying this it results in:
Failed while uninstalling JAX-RS (REST Web Services) 1.0.
org.eclipse.jst.javaee.web.internal.impl.WebAppImpl cannot be cast to org.eclipse.jst.j2ee.webapplication.WebApp
Later I found out that I can avoid the Maven compile error by inserting the according plugin into pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
I had similar troubles in eclipse and the only way to fix it for me was to
Remove the web module
Apply
Change the module version
Add the module
Configure (Further configuration available link at the bottom of the dialog)
Apply
Just make sure you configure the web module before applying it as by default it will look for your web files in /WebContent/ and this is not what Maven project structure should be.
EDIT:
Here is a second way in case nothing else helps
Exit eclipse, go to your project in the file system, then to .settings folder.
Open the org.eclipse.wst.common.project.facet.core.xml , make backup, and remove the web module entry.
You can also modify the web module version there, but again, no guarantees.
If you want to use version 3.1 you need to use the following schema:
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd
Note that 3.0 and 3.1 are different: in 3.1 there's no Sun mentioned, so simply changing 3_0.xsd to 3_1.xsd won't work.
This is how it should look like:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:web="http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee">
</web-app>
Also, make sure you're depending on the latest versions in your pom.xml. That is,
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
...
</configuration>
</plugin>
and
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
Finally, you should compile with Java 7 or 8:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
I had the same problem and fixed this by editing org.eclipse.wst.common.project.facet.core.xml.
In this file, I was able to change the following line
<installed facet="jst.web" version="3.1"/>
back to
<installed facet="jst.web" version="3.0"/>
That seemed to fix the problem for me.
I was running on Win7, Tomcat7 with maven-pom setup on Eclipse Mars with maven project enabled.
On a NOT running server I only had to change from 3.1 to 3.0 on this screen:
For me it was important to have Dynamic Web Module disabled! Then change the version and then enable Dynamic Web Module again.
Open Eclipse project properties, in Project Facets unselect "Dynamic Web Module",... Click OK
Maven -> Update project
In a specific case the issue is due to the maven-archetype-webapp which is released for a dynamic webapp, faceted to the ver.2.5 (see the produced web.xml and the related xsd) and it's related to eclipse.
When you try to change the project facet to dynamic webapp > 2.5 the src folder structure will syntactically change (the 2.5 is different from 3.1), but not fisically.
This is why you will face in a null pointer exception if you apply to the changes.
To solve it you have to set from the project facets configuration the Default configuration. Apply the changes, then going into the Java Build Path you have to remove the /src folder and create the /src/main/java folder at least (it's also required /src/main/resources and /src/test/java to be compliant) re-change into the required configuration you desire (3.0, 3.1) and then do apply.
I opened the project org.eclipse.wst.common.project.facet.core.xml and first changed then removed line with web module tag. Cleaned project and launched on Tomcat each time but it still didn't run. Returned line (as was) and cleaned project. Opened Tomcat settings in Eclipse and manually added project to Tomcat startup (Right click + Add and Remove). Clicked on project and selected Run on server....and everything was fine.
1) Go to your project and find ".settings" directory this one
2) Open file xml named:
org.eclipse.wst.common.project.facet.core.xml
3)
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.5"/>
<installed facet="jst.web" version="2.3"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>
Change jst.web version to 3.0 and java version to 1.7 or 1.8 (base on your current using jdk version)
4) Change your web.xml file under WEB-INF directory , please refer to this article:
https://www.mkyong.com/web-development/the-web-xml-deployment-descriptor-examples/
5) Go to pom.xml file and paste these lines:
<build>
<finalName>YOUR_PROJECT_NAME</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source> THIS IS YOUR USING JDK's VERSION
<target>1.8</target> SAME AS ABOVE
</configuration>
</plugin>
</plugins>
</build>
Go to Workspace location
select your project folder
.setting folder
edit "org.eclipse.wst.common.project.facet.core"
change installed facet="jst.web" version="3.0"

How to define in Eclipse Plugin WTP the context name of my app

I am working in Eclipse 4.2 and the WTP Plugin. I deployed my web-app on the integrated tomcat 7 server, but the context name is not as supposed. I want to name it moduleA but the current project name will be used as context name in the tomcat.
I already changed the Context-Root to moduleA in the Properties->Web Web Project Settings and I added
<properties>
<runtime.context>moduleA</runtime.context>
<m2eclipse.wtp.contextRoot>moduleA</m2eclipse.wtp.contextRoot>
</properties>
to my pom.xml
As I start my Tomcat it will always deploy it with the project name. Does someone know what the problem might be?
Thanks
Hello if you are using pom.xml with maven 3.. version.
you can use eclipse plugin like given below
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<wtpversion>2.0</wtpversion>
<wtpContextName>moduleA</wtpContextName>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
<classpathContainers>
<classpathContainer>org.eclipse.jst.j2ee.internal.web.container</classpathContainer>
<classpathContainer>org.eclipse.jst.j2ee.internal.module.container</classpathContainer>
</classpathContainers>
</configuration>
</plugin>
and give the desired context name in tag.

Tomcat 7 maven plugin additional context on tomcat7:run

When I run my web app inside eclipse using tomcat 7 maven plugin, I want an additional context to be deployed to tomcat. On the production enviroment this context is mapped to a directory outside tomcat dir using a context configuration
<Context path="/userimages" docBase="C:/test/userimages">
</Context>
And by this way is available in
http://wwww.myhost.com/userimages/test.jpg
How I achive the same on the development enviroment of the webapp (eclipse, tomcat7 maven plugin)?
In other words I want the contents of that folder to be accessible through
http://localhost:8080/userimages
or
http://localhost:8080/myapp/userimages
You should configure tomcat7-maven-plugin plugin.
Try this way:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<path>your_app_context_path</path>
<uriEncoding>utf-8</uriEncoding>
</configuration>
</plugin>
Then all your urls should start with http://wwww.myhost.com/your_app_context_path/...
More optional parameters for tomcat7:run goal can be found at apache tomcat maven plugin document
I found a workaround that doesn't do exactly what I originally wanted (publish another context using the tomcat maven plugin) but it solves my problem in a way. I add a folder "userimages" in the webapp folder of the application and this folder is used when developing. I prevent this folder from getting in the war and thus in the production server by using the "maven-war-plugin" with the following configuration in the pom.xml
<build>
....
<plugins>
....
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<packagingExcludes>userimages/</packagingExcludes>
</configuration>
</plugin>
....
</plugins>
....
</build>
Check also here and here

GWT/Eclipse/Jetty issue: Jasper can't resolve tag libraries

I'm trying to get GWT Hosted mode working in Eclipse, à la this HOWTO. Servlets work fine, as does my GWT code, but all my JSPs fail because with errors such as the following:
[WARN] /view/lniExecutiveSummary.htm
org.apache.jasper.JasperException: /WEB-INF/jsp/lni/lniExecutiveSummary.jsp(1,1) The absolute uri: http://java.sun.com/jsp/jstl/fmt cannot be resolved in either web.xml or the jar files deployed with this application
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
[ trimmed ]
This webapp works fine when deployed under Tomcat 5x; I just can't seem to get it to resolve the taglibs when running in Eclipse.
I'm new to Eclipse, and getting it working with all the moving parts required for GWT+Maven has me pulling my hair out.
Update: I'm no longer using Eclipse; I've switched (back!) to Intellij IDEA. So I can't honestly evaluate the answers you kind folks have posted. Once some voting action happens, or someone else reports success with one of these methods, I'll accept the appropriate answer. Thanks.
I feel your pain. I've gone thru the same pain trying to get gwt, maven, and eclipse to work together.
I've been able to get it working with maven using the following pom.xml. This way you can use mvn gwt:run to run in hosted mode, but unfortunately, I could never get the mvn goal mvn gwt:eclipse for generating an eclipse launch run time config to work.
Here's the relevant snippets from my pom.xml. Note that I've found it easier to install gwt in separate location and point maven to use that instead of having mvn download gwt from repo. The "system" level scope in the mvn dependencies are what make this happen.
<properties>
<!-- convenience to define GWT version in one place -->
<gwt.version>1.7.1</gwt.version>
<google.webtoolkit.home>${env.GWT_HOME}</google.webtoolkit.home>
<!-- tell the compiler we can use 1.5 -->
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<dependencies>
<!-- GWT dependencies (from central repo) -->
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>${gwt.version}</version>
<scope>system</scope>
<systemPath>${env.GWT_HOME}/gwt-servlet.jar</systemPath>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwt.version}</version>
<scope>system</scope>
<systemPath>${env.GWT_HOME}/gwt-user.jar</systemPath>
</dependency>
... other dependencies...
</dependencies>
<build>
<outputDirectory>war/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>generateAsync</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<runTarget>com.gwt.example/Application.html</runTarget>
<extraJvmArgs>-Xmx512m</extraJvmArgs>
</configuration>
</plugin>
<!--
If you want to use the target/web.xml file mergewebxml produces,
tell the war plugin to use it.
Also, exclude what you want from the final artifact here.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>target/web.xml</webXml>
<warSourceExcludes>.gwt-tmp/**</warSourceExcludes>
</configuration>
</plugin>
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<module>com.gwt.example</module>
</configuration>
</plugin>
</plugins>
...rest of pom.xml...
Another technique I've had success with is to use the eclipse google gwt plugin. Just use the wizard to create a new gwt project, make sure that you can run it from eclipse, then modify with your own code.
This webapp works fine when deployed under Tomcat 5x; I just can't seem to get it to resolve the taglibs when running in Eclipse. I'm new to Eclipse, and getting it working with all the moving parts required for GWT+Maven has me pulling my hair out.
You apparently have the JSTL JAR file(s) in Tomcat/lib instead of WEB-INF/lib. You can fix this in at least three ways:
Move/copy the JSTL JAR file(s) into WEB-INF/lib.
Move/copy the JSTL JAR file(s) into Tomcat/lib of your development machine.
Associate the right Tomcat server containing the JSTL JAR file(s) with web project in Eclipse. If not done yet, add the Tomcat server in Servers view. Then in project properties go to Java Build Path > Libraries > Add Library > Server Runtime > select the server in question.
Add the Jar files in eclipse project classpath. if you already had this file tomcat lib. This option will works for you. Second option is add jar in Web-Inf lib folder if you have eclipse web project.
Did you try to mark the "jsf-api.jar" as "exported" in your Java project ?
(as mentioned in this thread)
1.) Go into the java-project properties and mark the "jsf-api.jar" as exported.
(project>properties>java build path>order and exports)
2.) Go into the advanced global tomcat preferences and add your project to
the tomcat classpath (windows>preferences>tomcat>advanced>add projects to
tomcat classpath)
Then, try again to run your webapp under eclipse.
Here is an article describing the same procedure/setup, not for JSF but Hudson (same problem though)
You can clearly see the two steps I mentioned above:
(source: hudson-ci.org)
(source: hudson-ci.org)