jboss 6 - if the context root is specified in application.xml as well as in jboss-web.xml, which wins? - war

An application I am working on is encapsulated inside an ear file, which contains a jar (containing EJB files) and a war (having, apart from its normal contents, package hierarchy of action classes, directly inside it). The context-root is specified in both WEB-INF/jboss-web.xml as well as in META-INF/application, and, well... is different in both.
The interesting part is that if I deploy that ear file in JBoss 4.2, I am able to access the application by the context-root given in application.xml, whereas when I deploy it in JBoss-6.1, I can access my application only with the context-root provided in jboss-web.xml. Why is this happening ?
Could there be a rationale for specifying two different context-roots in the 2 xml files ?

Related

How to get the project base path in Spring mvc web application?

I have spring mvc web application which is deployed on a tomcat server. On that project, I want to create folders and files in the runtime. currently I can create folders in the server root by using System.getProperty("catalina.base"). But when I deployed the project in a externel server I cant create folders on the root level of the tomcat server beacuse I don't have permissions. Intead of that I decided to create folders in following directory.
tomcat_dirctory/webapps/myproject_directory
so I need to create folders and files in side the myproject_directory in the runtime. Can anyone tell me what is the path for that. May be I can hardocde that as follows.
System.getProperty("catalina.base") + File.separator + "webapps"+File.separator+"myproject_directory"
But Instead of hard coding I prefer to know is there any alternative way to obtain my project path.
You can use getServletContext().getRealPath("/");
Gets the real path corresponding to the given virtual path.
For example, if path is equal to /index.html, this method will return the absolute file path on the server's filesystem to which a request of the form http://://index.html would be mapped, where corresponds to the context path of this ServletContext.
The real path returned will be in a form appropriate to the computer and operating system on which the servlet container is running, including the proper path separators.
Resources inside the /META-INF/resources directories of JAR files bundled in the application's /WEB-INF/lib directory must be considered only if the container has unpacked them from their containing JAR file, in which case the path to the unpacked location must be returned.
This method returns null if the servlet container is unable to translate the given virtual path to a real path.

Tomcat or JBoss hosting 1 webapp with multiple websites

I want to have 3 websites, all with distinct public domain names but they all share a common java back-end SpringMVC server and use common static web resources like js and css files.
Rather than maintaining the UI code in 3 places, I'd rather run 1 server and deploy 1 WAR on a Tomcat8, Jboss or Wildfly cloud instance like OpenShift or AWS, but still be able configure my dns CNAME's to point to different paths on that WAR.
For example, here is where each domain would map to their respective endpoints but not have visibility of the others:
www.mydomainA.com ---> mycloudprovider.ip/sharedcontext/A
www.mydomainB.com ---> mycloudprovider.ip/sharedcontext/B
www.mydomainC.com ---> mycloudprovider.ip/sharedcontext/C
Is this possible? If so, what would be the steps to configure?
It is actually beneficial to configure 3 separate projects. They will all need to have their own application contexts, but can share a single parent POM. This will result in better load balancing performance. Also, since Amazon's pricing structure is such that it is cheaper to set up 3 micro instances than one powerful instance to run all 3 wars. Note: You can still have all 3 instances pointing to the same dataSource.
To solve the problem of duplicate webapp code, you can create a pom overlay using the maven-war-plugin. When Maven applies the overlay it will essentially apply a union of the files from your app with the files from the overlay. Any files that intersect will be used from the app rather than the overlay.
To solve the problem of duplicate java code, you can separate the common code into a new project and build a jar to use as a dependency.

One JVM per application WAR in Jetty?

I'm using Jetty 8 to run some servlets. I have two (or more) applications that share source code, and I want to run them on the same port (i.e., 8080). I have placed two different WAR files into Jetty, one.war and two.war, so that I access them at, for example,
http://localhost:8080/one
http://localhost:8080/two
Both WARS contain an identical common JAR file (common utils). Does each WAR application get its own JVM? Really, I just want to be sure that the common JAR classes are entirely separate, since some of the classes are static and I need the two applications to obviously not share access to the same static class.
This seems obvious, and I seemed to confirm that it is the case that the common classes are loaded separately for each WAR with a simple test scenario (two identical WARs hosted in the same Jetty instance, but at different paths...see above). But I lack written documentation or confirmation that this is the case.
Each WAR file will have its own class loader see http://docs.codehaus.org/display/JETTY/Classloading. So you can safely use static classes.

websphere ejb deployment issue : classnotfound error for other ejb references

I have two ejb jars packaged into a ear. say EJb1.jar adn Ejb2.jar. I am deploying it in Webphere 7.0. Ejb1 is referencing to classes in Ejb2.jar. Unless I specify the Ejb2.jar in Manifest.Mf file of Ejb1.jar, the deployment of EAR file fails.
Throws error that build path is incomplete and that referenced class is not found.
Is there any way I can overcome this ? Through some settings in WebSphere console?
I have too many ejb's in this ear referencing each other.
It makes things really difficult to update manifest file each time we make code changes.
Any ideas ?
If you want to avoid that what you need to do is create and EJB Client Jar which holds the interfaces and put it in the EAR/lib directory.
For example if EJB1.jar got MyBean.java and MyBeanLocal.java you will now split it to 2 jars files:
EJB1.jar (EJB Module) holding MyBean.java and EJB1-Client.jar (Utility Jar) holding MyBeanLocal.java
Then you put EJB1-Client.jar in the EAR file lib directory and EJB2.jar will be able to find the interfaces in its classpath.

problem with the injection of an EJB that resides in a jar

I have some problems regarding the EJB injection and I haven't been able to find a solution anywhere.
My situation is the following: I have an EAR file that includes a WAR and several JARs, all listed in the application.xml file. All is working fine for this part.
The problems come out when I try to add what we can call a “plugin system”.
I have a JAR with inside some .xhtml pages, backing beans and EJBs. This JAR, if needed, is inserted inside the EAR in a specific directory (let's call it “plugins”) and is detected from the application at startup.
When the JAR is detected it's path is added to the WAR class loader so all the pages and the backing bean are detected without problems. What is not working is the injection of the EJBs (I tried to use the notation #EJB, #Inject, the lookup...). I can't inject any of the EJBs that is inside the JAR plugin.
My guess is that the application server treats the JAR as a simple library module and doesn't look for any EJB inside it, so they are inside the JAR but not usable from the application.
My question is: there's a way of having this working? I tried to add the JAR in the EAR's MANIFEST.MF but nothing changed...
the application server i'm using is glassfish 3.0. About the application.xml: there's no reference in it about the JARs that are part of what i called "plugin system". This because i detect them when i deploy (or i restart) the application in the application server, so they may or may not be inside the system and i don't really know that before the system is started.
Each plugin JAR is a "collection" of pages and functionalities that can be added or removed from the system dynamically (more less like a real plugin system).
My EAR structure is the following:
MyApp.EAR
META-INF
lib
plugins
plugin1.JAR
app.WAR
logic1.JAR
logic2.JAR
for example: in the application.xml i have the references for app.WAR, logic1.JAR and logic2.JAR (they are always inside the system), at startup the application looks inside the folder "plugins" for any plugin (specific JARs) to be added to the system.
I hope i've been more clear about what i'm trying to do...
It seems that the EJB are not even registered in the JNDI tree of the server. Which application server are you using? You can have a look to this JNDI tree to see if the EJBs are there, but the way to do this depends on the specific server.
How are you declaring the JAR that contains the EJBs in the EAR application.xml?
It should be someting lide this:
<application>
....
<module>
<ejb>nameOfTheJarFile.jar</ejb>
</module>
</application>
The Jar should be in a the "/lib" directory of the EAR.
I hope this helps.

Resources