I have an EJB and a WEB module in my IntelliJ, created 5 entities that I would hope to load into a database using annotations.
I go to project settings, under modules, and select that I want to add JPA facet, I know have a EJB, WEB and JPA facet. I use eclipselink, so I checked that under JPA settings, I then added my persistence.xml file, configured the file.
Problem is that when deploying, it simply will not deploy the persistence.xml file, which means I can not find it under my glassfish 3.0 server when selecting my application under deployment descriptors. I only find my sun-web-ejb.xml under the EJB module. persistence.xml is not under the WEB module either, but I assume it should be under the EJB module anyway.
Is it intended that my persistence.xml should not be loaded on the server so that I can find the xml file under GF admin console (applications -> EJB module of mine -> deployment descriptors) ?
If this is not intended, is there anything in particular I need to do in IntelliJ to make persistence.xml being deployed on server? Maybe its something in particular I need to do with my JPA facet?
Thank you for any feedback on this, I can ofcourse provide more detailed information about my setup if neccessary.
I only find my sun-web-ejb.xml under the EJB module.
That's already weird. If I'm not wrong, this is a proprietary deployment descriptor for the Web module.
persistence.xml is not under the WEB module either, but I assume it should be under the EJB module anyway
It all depends on how you package and deploy your entities, which can be done in several ways (see What You May Need to Know About Persistence Unit Packaging Options).
If your entities are packaged in an EJB-JAR, the persistence.xml must be placed in the META-INF directory.
But you could package them inside the Web module, this would be simpler in your case. See the above link.
Is it intended that my persistence.xml should not be loaded on the server so that I can find the xml file under GF admin console (applications -> EJB module of mine -> deployment descriptors)?
I suggest to check that the physical JAR contains the META-INF/persistence.xml.
If this is not intended, is there anything in particular I need to do in IntelliJ to make persistence.xml being deployed on server? Maybe its something in particular I need to do with my JPA facet?
Can't say. Maybe the following link could help: Enabling JPA Support.
Related
Application structure description: Ear application with ejb module (.jar), jboss-seam (.jar) and war module (.war).
I have a StartupAction.class (seam component) annotated with org.jboss.seam.annotations.Startup. During application deployment I need to get the resource from application.war module root (application.war/pages/page.xhtml) and WEB-INF/classes (application.war/WEB-INF/classes/file.properties)
Jboss 4.2
Thread.currentThread().getContextClassLoader().getResourceAsStream("file.properties") would fetch the file from application.war/WEB-INF/classes/file.properties.
Jboss 7.1.1
Code from above doesn't work with Jboss 7.
I know that the class loading changed but I can't figure it out how to get into application.war in jboss 7.
Is it possible to do this? Are there any example of this?
Thanks in advance.
As mentioned by #BalusC, you will not be able to read a properties file that is embedded in a web module from any other modules (EJB or otherwise) that are packaged in your EAR.
The fact that this works in JBoss 4.x is a consequence of it providing backwards compatibility for even earlier versions of JBoss. Additional configuration is required in JBoss 4.x in order for it to use specification compliant class loading. JBoss 7.x and newer use specification compliant class loading by default.
If your properties file contains external configuration that is intended to be accessible after deployment then you might consider the approach described in How to put an external file in the classpath.
However, if it is effectively static data then you should package the properties file in a jar module and place it in the the lib directory of your EAR.
In jboss7, you have a classloader for each subdeploy.
In your case, Thread.currentThread().getContextClassLoader() will return the classloader of the current deployment.
To fix your problem, you could try this:
SomeRandomClassContainedInsideTheWAR.class.getClassLoader()
Check this guide to learn more about JBoss7 ClassLoader
https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7
I'm using Eclipse to create some basic jsp files with the help of Tomcat, and I was able to run and render a jsp file (on Mozilla Firefox), but then I read that one also should have a "deployment descriptor" file (web.xml), in order to "tell the application container how the web app should be configured".
I don't remember creating one, and I checked to see if Eclipse created a default one for me but couldn't find in anywhere in my project files...
Do I have to provide it, or is it just optional?
if you don't use deployment descriptor you have to use annotations in your classes which are supported in servlet 3.0 and higher
No it's not optional it is required to have a deployment descriptor in your deployed project. Since the deployment descriptor tells the application container how the web app should be configured.
So I am working on a project whereby we needed to create a custom Tomcat Realm implementation to read authentication credentials from a mongo backed datastore.
This has been pretty painless, but the implementation we have come up with has several dependencies on external libs i.e. scala libs, the java mongo-db driver, spring, salat (a mongodb ORM) etc....
Now in order for Tomcat to use this Realm we must deploy our Jar (and all the dependent jars) to tomcats lib folder.
Being pretty new to Java, I have no idea how much of an issue this is, but it doesn't seem nice to me. So really, my question is what issues would I have with dumping a load of JARs into Tomcats lib directory?
Cheers, Chris.
Most likely dependencies will become a problem. All JARs you place in tomcat/lib are visible to the WARs you deploy at a later time. I suppose your Realm implementation is the base for one or more web applications.
Let's say your Realm depends on Spring 2.0 and you're required to place those libs in tomcat/lib and afterwords you deploy a WAR using Spring 3.0. The WAR will see all classes available in tomcat/lib - the Spring 2.0 classes. So your WAR ships the 3.0 classes in WEB-INF/lib, at runtime it can see the Spring 2.0 libs in tomcat/lib as well as its own Spring 3.0 libs in WEB-INF lib. This is going to cause trouble...
I'm not aware of a simple solution for this, maybe you should have a look at OSGI and Tomcat integration. No question, it won't make life easier...
I plan to deploy an EAR packaged application into JBoss v4.2 as a folder containing the content of the EAR. Until now the EAR is deployed as a single file. I hope to be able to replace single JARs without the need to restart the application.
Is there any kind of event listener or annotation that can be used to register those JAR files upon deployment? The idea is a plugin like deployment of some features implementing a known interface. The plugins shall be used in a Seam webapp environment and may be exchanged with updated versions on the fly.
Any ideas? Thanks.
AFAIK, this is not possible/supported. When using an exploded EAR, touching an individual module would trigger the hot deployment of the whole EAR.
From Lightweight Java Web Application Development: Leveraging EJB3, JSF, POJO, and Seam:
3.4.2. Hot Deployment
Another JBoss feature that helps agile
development is exploded archives. The
EAR, EJB3 JAR and WAR files are not
necessarily JAR files in the JBoss
container. They can be directories
containing the contents of the JAR
file. For instance, instead of
deploying the dvdcatalog.ear file as a
single file, you can deploy it as
directory.
With the exploded directories, you can
make changes to any single JSP page or
Java class file in the application
while the server is running. Then you
can touch the META-INF/application.xml
file in the exploded directory (i.e.,
update the file's timestamp to
current) to re-deploy the entire EAR
application. This further saves
significant amount of time for rapid
turn-around agile developers.
What you're looking for doesn't sound simple. It would require detecting the change, unloading loaded class definitions coming from that JAR (assuming this information is known), reloading classes (something like that but I'm pretty sure I'm oversimplifying). Maybe more a job for an OSGI server.
See also
JBossClassLoadingUseCases
ClassLoadingConfiguration
I am maintaining following structure for my project
Web - Web Project
Model - EJB Project
Persistence - Java project having data classes and their mapping for Hibernate
Pokuri - EAR Project
As we know we can give jar file to hibernate configuration to load mapping information from jar. As I deploy EAR on to server I just want to build SessionFactory from mapping files in Persistence jar. But I am unable to get the path for that jar. Plz guide me to get the jar path. Or suggest me the best way to build SessionFactory and bind the same to a JNDI name.
Take a look at this thread - it may contain useful information.
Also, make sure your jar is mapped in your application.xml as an ejb module.