Deploy struts project in embeded jetty - struts

I'm embedding jetty in my application, the structure of the folder tree is:
|--lib
|--WebRoot
|---WEB-INF
|---lib
what I wonder is---where should I put the struts2 libs(e.g. struts2-core-2.2.3.1.jar, xwork-core-2.2.3.1.jar), and what about the servlet related api(e.g. servlet-api-2.5-6.1.11.jar, jasper-compiler-5.5.15.jar api)?
should I place jars in the top lib folder or in the lib folder inside WEB-INF?

This is really entirely up to how you want to structure your app, if you are embedding you don't have to follow a traditional webapp approach where you have a war file (exploded or not) and its convention of libraries under WEB-INF as in your example with a web.xml, you can skip the idea of a webapp deployer entirely and just build out the handler change yourself and register the servlets in java code, take a look at some of the embedded examples we have:
http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/ManyServletContexts.java
There are other examples in there as well, if you are embedding then unless you need to deploy wars you don't have to muck with that aspect of things. If you do need to deploy wars then you put things where the would be in any normal usage of a servlet container, things for just that war in the WEB-INF/lib and things in the system classloader back in your main primary classpath.

Related

Can Struts 1.x Resource Bundles be placed elsewhere than the classes directory?

This is for Struts 1.x (I'm using 1.3.10).
I've noticed that Struts is unable to pick up resource bundles in the ApplicationResources.properties file if it is not placed somewhere in the default classpath (e.g., com.abc.SomePackage).
For instance, if I put the ApplicationResources.properties file in a custom folder /WEB-INF/strutsResources and configure the struts-config.xml thus:
<message-resources parameter="/WEB-INF/strutsResources/ApplicationResources"/>
I've read that the resources need to be on the classpath so I've also tried adding the /WEB-INF/strutsResources folder to the classpath. It still does not pick up the resource keys.
I've double-checked that the strutsResources folder is actually deployed to the server (I'm using Glassfish v3), so the file is there, it's just not being parsed.
P.S.
If you're wondering why I'm trying to do this, I just wanted to organize my code a little better ("better," IMO). Since the ApplicationResources.properties file is not really a class, I wanted to place it in a resources folder by itself.
I've checked that placing the ApplicationResources file in a package in the src directory works just fine.
Ultimately, the answer is yes. You can play some interesting games by configuring a custom className and/or factory and get messages however you want (including from a database) and so on. This allows you to customize whatever you want*.
I agree the resources aren't a class, but putting them on the classpath is a common practice, and allows resources to be loaded as a resource, e.g., from inside a jar. I'm sympathetic, but I'd leave it as-is.
*Like reversing all the text; a fun prank to play on your co-workers and QA department.
Its best leave it on the classpath.
It's stadard practise to include properties files on the classpath, especially if you're planning on packaging it up in your WAR/EAR. You're keeping it under WEB-INF so you gain no benefit from moving it off the classpath, and you'll just confuse other developers who have to work on the project and you've had to put a hack in to make this work.
If you want to keep your files external to your deployable WAR/EAR then that's a valid reason for not using the classpath. Typically this will require some configuration as part of your deployment to specify where the file is to reside.
For example specify the location using
a JVM argument (e.g. -Dprops.file=/config/myapp.properites)
lookup from a JNDI resource
use a PropertiesFactoryBean if you're using the Spring framework (I
use Spring's ApplicationContext with Struts 1 MVC)
read properties from a database writing your own
ApplicationPropertiesDAO class that initialises itself durnig your
applications bootstrap process (e.g. Spring application contact,
Servlet in web.xml, Listener in web.xml, etc)

Glassfishv3 not adding jars in ear to the classpath

I have been working on this problem for one whole day but in vain without any effective solution.
I have an ear file packaged with an ejb and a handful of jar files (including hibernate and the other dependent jar files).The ejb is stateless and enabled as a web service.
The ear file has been packaged using maven and has the below structure
ear->projectrelatedejb.jar
->hibernate.jar
->otherdependent. jar
->META-INF/application.xml
->META-INF/manifest.mf
The application.xml and manifest file are automatically generated by maven when I do a package.
When I deploy this ear file on glassfish it gets deployed with the ejb methods being accessible using web services. However when accessing the application (using soapui),
the ejb methods that perform some database functionality using hibernate throw java.lang.NoClassDefFoundError for the hibernate api during runtime.
It is obvious from the error that the hibernate jars are not on the classpath during runtime but since the jars are within the ear Glassfish should have
added it to the application classpath.
I tried various options like adding the classpath entries to the manifest.mf during the package (by using the element addClasspath with the maven-ear-plugin) which didn't do any good.Also with Glassfish we cannot add the dependent jars as modules to the application.xml unless the jars are application client jars
(Glassfish wouldn't deploy the ear file if the application.xml has the dependent jars declared as modules).
I also tried placing the jars in the lib directory within the ear (which isn't actually required) and with the manifest Class-Path header referencing the jars in the lib directory which also didn't fix the problem.
The quick and dirty fix which I can do to get this working is to place the hibernate and the other the dependent jars in Glassfish's lib directory.However,this is a bad practice
and I am somewhat reluctant to do it.
I would really appreciate if someone can provide me with a working solution to this problem.I have gone through the net looking for this problem
but couldn't find any solution.
Wondering if its a bug with glassfish or does glassfish need something special to reference the jars in an ear.
Thanks in advance.
I found a similar problem which is discussed here: http://www.tricoder.net/blog/?p=59.
Simply put, try putting the libraries in EAR/lib directory and according to JEE5 spec, glassfish will add them to class path automatically.
I used Server Library option to deploy application JARs and it worked for me.
Right click on your EAR-> Properties -> Libraries-> Add Library -> Create -> give name and change type in Library Type to Server Libraries then add JARs that should be deployed and confirm.
I work with NetBeans 7.0.1 and GlassFish server 3.1
When you say you added classpath entries to manifest.mf, which manifest.mf do you refer to? The one in ear-root/META-INF/manifest.mf ? Try adding a META-INF/MANIFEST.MF to your ejb module with Class-Path entries!

How do I get artifacts from one Maven module included in the resources of another in my build?

I have Maven modules that produce a Flex application as an SWF file. I want to include that file in a web application that is made with another Maven module from the same build. I'm wondering how and at which lifecycle phase I get Maven to grab the artifact from the other module and put it insode the appropriate folder of the webapp module. Would I use a separate assembly module?
The web app is running on a Jetty server in an OSGi environment (using Pax), the server side of the web app uses Struts. The final artifact as I see it would be a WAR file including my Action etc classes, JSP templates, static contents such as CSS or JS, and the SWF movies. I might be better off with these split over some other setup, but right now, I wouldn't know which.
I'm wondering how and at which lifecycle phase I get Maven to grab the artifact from the other module and put it insode the appropriate folder of the webapp module.
What about using dependency:unpack dependency:copy during prepare-package?

What are some Maven project naming conventions for web application module?

When creating a project with the webapp archetype in Maven, they subtly advise not putting any Java source in the webapp project by not including the "src/main/java" folder.
What do you name your Maven projects?
project-webapp for the project that contains the JSP, CSS, Images, etc.
project for the project that contains domain specific entities
? for the project that contains the web application files like Servlets, Listeners, etc.
My first inclination would be to use "webapp" for the project containing the web application files (Servlets/Listeners), however the archetype uses "webapp" to convey the JSP/CSS/Images project and would cause confusion to other developers.
When creating a project with the webapp archetype in Maven, they subtly advise not putting any Java source in the webapp project by not including the "src/main/java" folder.
That's not really true. When you create a project with the maven-archetype-quickstart, you don't get a src/main/resources directory. Would that mean you should not put resources in this project? No.
What do you name your Maven projects?
There is no general rules, nor conventions. Use something that makes sense for your organization and your team. But as I said above, your initial assumption is not true and putting Java code inside a maven war module is a common practice (except for code you want to share between modules).
Not sure if this below link directly answers your question, but it makes sense to refer it
Refer their JIRA task here Document the naming convention for archetypes
As per this, the naming convention can be as below
The Artifact id of the archetype should be of the format -archetype-
Ex: + maven-archetype-quickstart : Which indicates the archetype is from maven and the project is a quick start
Same way you scala-archetype-simple : Which indicates it is from scala and is a simple scala project
Best of luck

Netbeans does not see custom *.tagx in my Maven war dependency

I have this scenarion in my project:
Maven2 for dependency management
One project 'common-web' (war) contains all images, css files, js files, layout files etc. It also contains custom tags (*.tagx files) that we use in our project. They are located in WEB-INF\tags direcotry.
Second project (also war) has dependency on common-web, we use those custom tags in our *.jsp files by importing them in this way:
<%# taglib prefix="custom" tagdir="/WEB-INF/tags" %>
This works great in runtime, but is a big problem during development, because NetBeans does not see those custom tags and does not give me Intellisence.
In Eclipse I managed to work around this issue by linking tags directory in this second project. Can I do something similar in NetBeans? Or is there any better way to work around this issue?
I'm no NetBeans export so apologies if this makes no sense, but I understand from this article that it will discover taglibs in referenced jars.
Would it be possible to move the shared tags into a jar and reference it in both wars instead of trying to have one war reference another? If the taglibs jar project is deployed to the Maven repository it would be managed by Maven and available to both projects.