Maven web project issue - eclipse

I'm using Eclipse IDE for EE development(Kepler SR1).
Using Maven 3.1.0, I'm trying to create a simple web project. Accordingly, in Eclipse, I select maven-archetype-webapp and proceed.
But when the project is created, under 'Java resources', only src/main/resources is seen. When I check the build path, it shows src/main/java and src/test/java as missing.
Obviously, when I created a simple servlet under src/main/resources, I got a ClassNotFoundException for the servlet - I believe that the Servlet class didn't get compiled as my Maven basic folder structure itself is missing !
What could be the problem? I don't see any reason to make/create any source folder entries manually if I'm getting the option of 'maven-archetype-webapp' in the Eclipse IDE.

There's nothing in the documentation to suggest that the maven-archetype-webapp archetype will create a servlet class for you.
The documentation for this archetype shows this structure as the end result:
project
|-- pom.xml
`-- src
`-- main
`-- webapp
|-- WEB-INF
| `-- web.xml
`-- index.jsp
The archetype description does state that is a "An archetype which contains a sample Maven Webapp project.", and it certainly is.
You'll need to use another archetype, or create your own. An alternative approach is the Eclipse WTP integration to eclipse-ify your maven project. It's been a while since I tried, but iirc that worked pretty well.

Related

JPA configuration - persistence.xml is automatically created under src/main/java instead of src/main/resource

I am using Maven 3.3.9 and created a Maven Web Project in Spring tool suite and using Eclipse.
Recently I went through a Tutorial for configuring JPA with maven project.
Tutorial showing JPA configuration
I successfully configured Database connection using EclipseLink2.5
PROBLEM I AM FACING IS
After I click ok followed by configuring JPA 2.1 using project Facet properties. Persistence.xml is created automatically under META-INF of src/main/java instead of src/main/resource location.
Is this correct ??
I had already researched a lot on this, in every blog it is mentioned that META-INF should be placed under src/main/java and not under src/main/resource.
Then why is it every time I create a Maven project and configure JPA from Project Facet, Its ends up automatically creation under src/main/java.
please refer my screenshot.
So should I remove this folder META-INF/Persistence.xml from src/main/java and paste it manually under src/main/resource.
I always move META-INF to src/main/resources. Everything is going to be happier with things configured that way.
Where do I put META-INF in Eclipse?.

transitive dependency using GWT Plugin Eclipse

I have Project A which is a GWT Project with RPC stuff. The Server part Depends on a Project B and that project (B) depends on some thirdparty ABC.jar's
When i Run the GWT project with Run/Debug the ClassPath doesn't contain the ABC'jars - only the compiled classes from Project A and B is in the WEB-INF/lib folder and the GwtServlet.jar.. thingy.
Any help would be very welcome ..
ps: We are not using Maven and wont be using it in any near future ...
put ABC.jar into the war/WEB-INF/lib folder
https://developers.google.com/web-toolkit/doc/latest/DevGuideOrganizingProjects
I you cannot use Maven in your project for dependency resolution and don't want to manage them by hand Apache Ivy (+Ant) may be another option.

JSF 2.0 app does not find resource

I am new to developing on JSF (and new to web development in general) and I am trying to put an image on a page.
I'm developing my JSF app in Eclipse and running it on Glassfish 3.1.2. I have registered Glassfish as a server in Eclipse, and running the app via Eclipse.
I use the following markup on my xhtml page:
<h:graphicImage library="images" name="logo.png"/>
I copied the image in META-INF/resources/images/logo.png .
The image does not appear on the page and when I view the page source I see the element
<img src="RES_NOT_FOUND" />
indicating that the image is not found.
When I export my app to a war file and deploy it onto Glassfish via the autodeploy folder, I get the same results - the page displays, but the image does not appear.
Can anyone advise why the image resource is not found?
I copied the image in META-INF/resources/images/logo.png
This location will only work if the project represents a standalone module JAR which ultimately ends up in /WEB-INF/lib of the WAR.
This does not seem to the case in your particular case. Nothing in your question indicates that you're indeed developing a module JAR file. Apparently you've placed it straight in the WAR this way. This is not right.
You need to put the /resources folder straight in the public web content, not in the META-INF folder.
WebContent
|-- META-INF
|-- WEB-INF
| |-- faces-config.xml
| `-- web.xml
|-- resources
| `-- images
| `-- logo.png
`-- index.xhtml
See also:
Structure for multiple JSF projects with shared code
Why some resource files are put under META-INF directory
Unrelated to the concrete problem, using images as library name does not look entirely right. Just use
<h:graphicImage name="images/logo.png"/>
See also:
What is the JSF resource library for and how should it be used?

How to convert properly Eclipse project to Maven project?

I have created in Eclipse Dynamic Web Project. Then I have selected option 'Convert to Maven Project' from 'Configure' from right-click menu. And now I can see red errors on Java Resources folder in my project. But none subfolder is with red error. In which way can I resolve that problem? I am using Eclipse Juno and m2e plugin.
I have recognized that m2n plugin haven't created src/main/java, src/main/resources and src/main/webapp directories in Java Resources. But the error is still the same.
The process in manually. You need to create a pom.xml and change your folder structure to follow Mavens conventions. I would recommend to create a web project via maven archetypes and move your project step-by-step into the new structure.

Eclipse and Maven configuration

I'm new to Maven. I've just installed and configured it.
When I started coding, I realized Eclipse doesn't show the error messages.
I haven't found anything helpful by searching Google. Some sources say to add java builder to your project but I already did.
Here's a screenshot.
It looks, that you had project in eclipse configured to have source code in 'src' subdirectory (and compile classes to 'bin').
Maven by default looks for java sources in src/main/java (and compile classes to 'target/classes').
So you'd need to move your source code to src/main/java or modify pom.xml to point to 'src' as source directory.
I'd suggest following maven convention and store source code in src/main/java.
You didn't create the Maven standard folder structure.
Create the structure like that:
src/main/java for Java classes and src/main/resources for properties etc., then do a right click on the project and choose Maven -> Update project configuration.