Deploying an EAR with EJBs and dependencies on JBoss - jboss

I'm trying to deploy a maven generated ear in a fresh installed Jboss EAP 6.1. The ear deploys well on Glassfish 2.x. The ear structure is this:
Ear_name-deploy-X.X.X.ear
|- META-INF
| |- maven
| | |
| | \-Ear_name -> Ear_name-deploy -> pom.properties
| | -> pom.xml
| |- application.xml
| |- MANIFEST.MF
| \- sun-application.xml
\- some jars (around 100)
Some of those jars are EJBs wich have dependencies on other jars in the same bundle and those dependencies are failing. I know I have to include a jboss-deployment-structure.xml file in META-INF folder. But I don't find how to define those dependencies without having to establish the jars as modules, what I don't want to do. Isn't there another way to stablish those dependencies? Thank you all for your time.

Related

JSF annotations ignored with imported project [duplicate]

I have two JSF projects that share a lot of code - java classes, xhtml files, tag libraries, css and javascript files etc. My dev environment/platform consists mainly of Eclipse, Ant, Perforce and Tomcat.
Has anyone found a way to create and organize the shared code so that the common code can stay within one set of folders?
Eclipse makes it easy to add external folders for java sources, but falls short on the other file types. I'd appreciate any ideas.
Create a new "Java Project" in Eclipse. Add it as another project to the Deployment Assembly property of the main dynamic web project. This way it will automatically end up as a JAR in /WEB-INF/lib of the build of the web project. Since newer Eclipse versions, you can also create the project as "Web Fragment Project". This way the Deployment Assembly step will be done automatically.
Put all those shared resource files in /META-INF/resources folder of the Java project. Just treat it like WebContent/resources of the main web project. Tagfiles can just be kept in their own /META-INF/tags folder.
E.g.
CommonWebProject
|-- META-INF
| |-- resources
| | `-- common
| | |-- css
| | | `-- some.css
| | |-- js
| | | `-- some.js
| | |-- images
| | | `-- some.png
| | |-- components
| | | `-- somecomposite.xhtml
| | `-- sometemplate.xhtml
| |-- tags
| | `-- sometag.xhtml
| |-- beans.xml
| |-- faces-config.xml
| |-- some.taglib.xml
| |-- web-fragment.xml
| `-- MANIFEST.MF
:
with
<h:outputStylesheet library="common" name="css/some.css" />
<h:outputScript library="common" name="js/some.js" />
<h:graphicImage library="common" name="images/some.png" />
<common:somecomposite />
<common:sometag />
<ui:include src="/common/sometemplate.xhtml" />
...
In case you're using Maven, the /META-INF folder has to be placed in src/main/resources and thus NOT src/main/java!
If you want to trigger the JSF annotation scanner as well so that you can put #FacesValidator, #FacesConverter, #FacesComponent, #FacesRenderer and consorts in that project as well, then create a /META-INF/faces-config.xml file as well. Below is a JSF 2.3 compatible one:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd"
version="2.3">
<!-- Put shared faces-config.xml config here. -->
</faces-config>
The /META-INF/web-fragment.xml is mandatory for the JAR to be recognized by the servletcontainer as a "Web Fragment Project" and should already be generated by your IDE, but for sake of completeness here is how it should look like for a Servlet 4.0 compatible one:
<?xml version="1.0" encoding="utf-8"?>
<web-fragment
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-fragment_4_0.xsd"
version="4.0">
<!-- Put shared web.xml config here. -->
</web-fragment>
That's all.
See also:
Splitting up shared code and web.xml from WAR project to common JAR project
JSF facelets template packaging
Obtaining Facelets templates/files from an external filesystem or database

Maven: how to build jar and include as a dependency

I have a multi module project. I am using eclipse and Maven 3. I wish to first build a jar (a standalone project with its own pom). This is not the problem.
The problem is this jar is included as a dependency of my multi-module EAR project (used by two of the wars). The code of the JAR will often change and will require building before the EAR project is built.
How can I make this jar build prior to the EAR build in one action?
Here's my setup:
parentProject (packaging=pom, dependency[filters down to wars]=jarProject)
earproject (packaging ear, parent=parentProject)
war1Project (packaging war, parent=parentProject)
war2Project (packaging war, parent=parentProject)
jarProject (packaging=jar, no parent)
Add your jar project as topmost <module> in your multi-module EAR project's POM.
See also Maven: The Complete Reference, Multi-module vs. Inheritance.

Can maven treat WEB-INF\lib the way eclipse (and m2e) does?

I have a servlet/jsp web project which runs fine on eclipse and is exported as war fine (once I clean it that is). I mavenized the project deleting all of the dependencies from the WEB-INF\lib folder except a homebrew jar (the output of another project in the workspace). When I run the package maven goal I get messages for missing classes from this jar:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
#..... NOTICE THIS COMES FROM A CUSTOM JAR
[ERROR] /C:/path/DataServlet.java:[3,30] package xxx.java.helpers does not exist
Now this has been asked before and the most rigorous solution appears to be to create a local repo: Can I add jars to maven 2 build classpath without installing them? (NB: I am at maven 3).
I would like to avoid this - so is there any way maven will just stuff this jar to WEB-INF\lib in the war ?
Solutions that use some maven plugin to cp the contents of the WEB-INF\lib in the war are welcome - although I just have this feeling that there should be a solution that takes into account the "special" nature of this folder.
Observations:
Alt+F5 removes this line:
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
which corresponds to the "Web App libraries" in the Java Build Path. So not only maven refuses to take into account the WEB-INF\lib - it also breaks the build path of eclipse completely.
Related:
Maven: How to include jars in Eclipse, which are not available in repository?
Uses the maven eclipse plugin : update my classpath with an Eclipse User Library via the maven eclipse plugin - not compatible with m2e
How does the m2e eclipse plugin interact with eclipse? - apparently m2e checks the pom then calls the eclipse builders (hence the .classpath is read)
Eclipse maven-enabled web app references workspace projects, but those are not deployed when running Tomcat server
Deploying a Maven project with dependencies to Tomcat or Jboss running within Eclipse
Did you add this jar from WEB-INF\lib as a dependency like this:
<dependency>
<groupId>someGroupId</groupId>
<artifactId>someArtifactId</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/webapp/WEB-INF/lib/homebrew jar</systemPath>
</dependency>

Integrate Maven with existing Java Project using Eclipse

I have created this Java project using struts, hibernate in Eclipse Helios,
Now I want to integrate this project with Maven how to do it?
I have installed Maven In Eclipse already.
Tutorials, blogs, websites that I have found so far are explaining integration of some project into Maven outside Eclipse and then importing it in Eclipse or crreation of New project with Maven.None of them so far addressing my Problem.
As I mentioned I have created a project in Eclipse already Now I just want to integrate it with Maven, how to do it?
In eclipse you can easily convert a java project in a maven one right clicking on project -> configure -> convert to maven project.
While an IDE "importer" can sometimes be handy, it is not required to turn a project in Eclipse into a maven project. Basically all you just need is to add a pom.xml file and follow maven's conventions - or configure it.
By using the maven-eclipse-plugin it is actually possible have a maven itself generate the necessary files to integrate your maven project with eclipse:
Start from the command line
Go to your project's root
Create a new pom.xml file from a simple template or initiate a new project folder structure (including a pom) using mvn archetype:generate
Type mvn eclipse:eclipse.
Then maven has generated the necessary files to integrate with eclipse.
That said, maven by convention expects a certain folder structure of your Java project. It looks like this:
my-app
|-- pom.xml
`-- src
|-- main
| `-- java
| `-- com
| `-- mycompany
| `-- app
| `-- App.java
`-- test
`-- java
`-- com
`-- mycompany
`-- app
`-- AppTest.java
So unless you already have this structure, you need to move your source code to main/java (and unit test code to test/java).
Further if your project has dependencies to other projects; then you need to express these dependencies in Maven's pom.xml file. If your dependency projects are stored in the Maven Central this is particularly easy. To express a dependency to e.g. Apache Commons - you would add this to your pom.xml:
<project>
...
<dependencies>
...
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
...
</dependencies>
...
</project>
After these initial attempts to integrate your project with maven, you can try to build with mvn compile from either the command line - or using the m2eclipse plugin for Eclipse.

How to manage shared resources for several web apps in Maven AND Eclipse?

Note: I didn't get any response in the first version of this question, so I modified it to be more generic...
Context
My project is divided into several maven modules and several web-applications. Here is the structure:
my-project
+ pom.xml
+-- commons
+-- persistence
+-- ...
+-- web-app-1
+-- web-app-2
+-- ...
All the web applications share common resources, such as JS, CSS and images files.
Instead of duplicating these resources in each web-app-X, I decided to create another project called web-resources, which is a WAR project.
The structure is then the following one:
my-project
+ pom.xml
+-- commons
+-- persistence
+-- ...
+-- web-app-1
+-- web-app-2
+-- ...
+-- web-resources
+-- pom.xml
+-- src/main/webapp
+-- web.xml (which is almost empty, just need to be present for Maven)
+-- web_resources
+-- css
+-- images
+-- javascript
Maven
In Maven 2 (or Maven 3, as I just migrated my project to maven 3.0.2), this configuration is easy to manage as all web-app-X declare web-resources as a dependency:
<groupId>foo.bar</groupId>
<artifactId>web-app-1</artifactId>
...
<dependencies>
<dependency>
<groupId>foo.bar</groupId>
<artifactId>web-resources</artifactId>
<version>${preclosing-version}</version>
<type>war</type>
</dependency>
...
So when I build my WAR project, it first get the web-resources.war (built just before), unzip it, and build on top of it the web-app-X web-application.
This way, my WAR file will contains also a directory called web-resources/ that contains the shared resources.
This is the war overlay principle.
So on a Maven point of view, everything is fine!
Eclipse
Now, here comes the main problem: having a good Eclipse configuration.
Question: How can I use my current configuration to be managed correctly by Eclipse? In particular, when I deploy any web-app-X in Tomcat using Eclipse...
Note that I want to get the more automatizable (?) configuration, and avoid any manual steps, as this configuration should be used by dozens of developers...
For me, the best solution seems to use the linked resources of Eclipse. Thus, I set the following configuration in my web-app-X pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<wtpversion>1.5</wtpversion>
<linkedResources>
<linkedResource>
<name>web_resources</name>
<type>2</type>
<location>${project.basedir}\..\web-resources\src\main\webapp\web_resources</location>
</linkedResource>
</linkedResources>
</configuration>
</plugin>
...
When I run the mvn eclipse:eclipse configuration, it adds succesfully this information in my .project file:
<projectDescription>
...
<linkedResources>
<link>
<name>web_resources</name>
<type>2</type>
<location>C:\dev\project\web-resources\src\main\webapp\web_resources</location>
</link>
</linkedResources>
<projectDescription>
Now, I import my project in Eclipse.
Problem: in Project properties > Java Build Path > Source, I don't see the Link Source present.
I only see my four Maven default directories (src/main/java, src/main/resources, src/test/java and src/test/resources).
What is strange is that when I try to manually add the linked resources, it refuses and says that it already exists...
So when I deploy my web application on my Tomcat in Eclipse, it does not deploy the web_resources directory, and thus I don't get the CSS / JS / images deployed.
After some tests, it seems that I have to do two modifications:
Add the line <classpathentry kind="src" path="web_resources" output="src/main/webapp/web_resources"/> in my .classpath file;
Remove the <project>preclosing-web-resources</project> in the .project file.
Note that using this configuration, Eclipse will copy (and keep synchronization) the content of web_resources project in my web-app-X/src/main/webapp/web_resources, but this is not a problem (this directory is ignored by the SCM).
The only automated solution I found was to create a simple Maven plugin that do the two previous modification, and then run the following command (or use a .bat file):
mvn eclipse:clean eclipse:eclipse myEclipsePlugin:eclipse
Question
Is there a better way to manage such configuration?
Technical information
Java 6, Maven 3.0.2, maven eclipse plugin 2.8, Eclipse 3.3.2 (but I can test with newer version of Eclipse), no m2eclipse plugin.
Starting with Servlet 3.0, you can share resources by putting them within the src/main/resources/META-INF/resources directory.
When the webapp deploys, Servlet 3.0 makes those resources available from the context path. For example, in your case...
web-resources
-- src
---- main
------ resources
-------- META-INF
---------- resources
------------ css
-------------- global.css
------------ images
-------------- background.png
Let's assume that my_project has a dependency on web-resources and is deployed to the url http://my.localhost:8080/myProject.
With that configuration, the following URLs will resolve to the correct resources:
http://my.localhost:8080/myProject/css/global.css
http://my.localhost:8080/myProject/images/background.png
IF you have a name conflict between the resources and your actual application, the application will win.
Be sure your web.xml states you are using Servlet 3.0
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
You might want to take a look at this blog post. It covers a method for sharing resources using maven:
http://www.sonatype.com/people/2008/04/how-to-share-resources-across-projects-in-maven/