Eclipse WTP: Glassfish does not include WEB-INF/lib in classpath - eclipse

I started a new dynamic web project in eclipse helios. I integrated glassfish into eclipse and it works fine so far. Except one thing:
I place my libraries (jdbc, log4j etc.) in WEB-INF/lib. Eclipse deploys that files correctly to glassfish, but glassfish does not include that directory in its classpath, so my app won't run (because it can't find the jars).
When I edit the server's "launch configuration" in eclipse, I can manually add the libs under "Classpath", but that don't change a thing.
Only when I manully copy the jars to glassfish's lib/ext folder, the libs are included.
When I used tomcat as a server it works, the libs are in tomcat's classpath. But I want to use glassfish without copying the libs manually.
Any idea?

Not sure how do you add the libs in your project.
Try to show the project properties tab, select the Deployment Assembly node section, and click the add button. Select archives from file system or project (if your lib i also an Eclipse j2se project).
This should work.
Hoping you use the latest Eclipse 3.6 SR1 and the latest glassfish plugin from the update Center: http://download.java.net/glassfish/eclipse/helios

My servlet did not find the jdbc driver, so I thought it was a lib missing. Calling “ClassForName“ solved the problem. This seems strange to me, as this is not needed when used in the SE context.
So eclipse is correctly deploying the libs, just a little extra code is needed.

Related

CDI imports cannot be resolved in Eclipse

i have written an application on my pc using CDI as the backing bean for jsf, the application works completely fine.
Now i setup everything on a new pc, installed glassfish 4.1, setup eclipse kepler by putting the installed jre as jdk7 from the glassfish folder.
when i make a war for the application on my pc and deploy it onto the glassfish server on the other pc everything works fine.
now i tried taking the project from my pc and imported it onto the new pc. the eclipse on the new pc wont recognize import javax.enterprise.context.SessionScoped; giving compiler error that this annotation is not available.
The import javax.enterprise.context cannot be resolved
it doesnt recognize javax.enterprise.context.* at all. like CDI is not available. i am using JDK 7 which contains JSR 346, so i am completely confused what the issue could be.
if i deploy the application directly through the glassfish admin console using the war file it works perfectly fine but if i try to publish it through eclipse, it gives me unresolved compilation errors
Eclipse did not import ALL glassfish jars, so you need to:
Right Click on the project name, Build Path, Configure build path, under Libraries Click Add External Jars, go to where you have extracted Glassfish and import all jars that exists in:
glassfish4\glassfish\modules
and all sub directories two, like endoresed.
This will fix the problem for CDI and other stuff lik JAX-RS
If I had to guess, your .project and .classpath files are pointing to JAR locations that are specific to your old computer.
This is why people like build tools such as maven, or gradle, you can pick up and reimport a project; it'll resolve all dependencies for you.
Do you happen to use the GlassFish Tools plugin for Eclipse? I found that the GlassFish System Libraries classpath container, which is created implicitly by that plugin and which is added to all projects that specify a GlassFish server as their runtime, misses cdi-api.jar. This is where the javax.enterprise.context.* package is located (and many others).
So I could fix this by adding cdi-api.jar as an External Jar to the build path. After that, you may get a warning like Classpath entry [...]/cdi-api.jar will not be exported or published. Runtime ClassNotFoundExceptions may result., which can be eliminated by using the Quick Fix to Exclude the associated raw classpath entry from the set of potential publish/export dependencies. That JAR file is already contained in the modules folder of GlassFish, obviously.
Maybe this problem only occurs with the GlassFish Web Profile, at least that's what I use.

Eclipse-Kepler, Maven and Setup Tomcat 7 debug (hot deploy)

I have maven based project with following structure:
main_project
module_webproject
module_java_proj_1
module_java_proj_2
module_java_proj_3
... ...
Everything compiles and packages fine with command line maven goals execution. I need to setup this project into eclipse environment for developers with tomcat deployment. Anyone know setup instructions?
Also, i am looking into tomcat hot deploy for debugging capabilities.
I have tried mvn eclipse:eclipse, this does only creation of .project and .classpath files. But projects directories are not treated as java or web projects.
Answer from following forum some what helps...
[Running Maven project on Tomcat from Eclipse
There can be a few reasons why you don't see the project in the Add/Remove projects dialog for Tomcat. Verify the following:
You have m2e installed (http://eclipse.org/m2e/download/)
You have m2e-wtp installed (http://www.eclipse.org/m2e-wtp/download/)
Your Maven project imported as a Dynamic Web Application. Look for a Deployment Descriptor entry when you expand the project, it should be somewhere in the first few entries. It is the second one down for me on Eclipse Juno. Not there? It's probably not a web app. Go back and verify 1 & 2, then remove and re-import your project.
Make sure that your web application is not too new for the version of Tomcat that you are using. Right-click the project and go to Properties > Project Facets. Look for Dynamic Web Module and check the version. If this version is too new for your Tomcat version, Eclipse won't let you add it. For instance, your Dynamic Web Module version is 3.0 and you're using Tomcat 6.

Maven WebApp deployed inside WTP (Eclipse) Tomcat: META-INF/context.xml is not copied over (is ignored)

Disclaimer: this is not a duplicate of the "why isn't my JDBC resource declared in META-INF/context.xml taken into account" genre questions.
I have two Java EE web applications:
one is created inside Eclipde IDE using Eclipse's "Web Application Project" template
the other one is created using Maven, and then imported into Eclipse
Inside Eclipse I also have a Tomcat configured using the WTP Plugin, such that I can easily (or so I hoped) deploy my Eclipse Web Apps in there in a "one button push" way.
For each of the above described applications, I have a context.xml file placed in their META-INF directory, in which I declare some JDBC datasources as JNDI resources.
The Eclipse created application works fine when deployed in the WTP Tomcat inside Eclipse. I right-click the Tomcat server in Eclipse, add the project, start it and it all works fine, the JNDI datasources are found etc.
For the other project, the one created with Maven and imported inside Eclipse, if I add it to the WTP Tomcat, and manually specify where the war file was built by Maven (in the "target" dir) it seems to work, but the JNDI datasources are not found, more specifically, my Spring declared datasource:
<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/whatever" />
throws an exception saying no JNDI name is bound for "whatever".
If I deploy the very same war file in a "regular" Tomcat (just un unzipped Tomcat, no Eclipse involved) it works fine and the JNDI datasource declared in the war's META-INF/context.xml is found.
I've looked inside Eclipse's Tomcat working dir, and sure enough while for the Eclipse created project the context.xml file is copied inside "{catalina home}\wtpwebapps\eclipeProjectName\META-INF\context.xml", there's no such file (and folder structure) for the Maven project.
My question is then: does anyone know how you can have a Maven-created web app imported inside Eclipse and deployed in WTP Tomcat such that the META-INF/context.xml file is taken into account?
As you've mentioned that you are using the Eclipse Helios. There is a alternative one provided by JBoss as the Eclipse Update Site. The document told us as the following: -
The following folders should never be removed as they are part of composite
requirement sites used for current/previous JBoss Tools releases:
Helios SR2: 0.13.1
Indigo SR2: 0.15.3
Juno (SOA Tooling Integration Stack ONLY - may not be needed much longer?): 0.14.0
Juno SR1 (can be removed when we have a Juno SR2 target platform instead, if anything newer exists): 0.16.0
Please note, before the Eclipse Juno, I used Helios and Indigo with this plugin. It also gives me a good result.
I hope this may help.

Eclipse glassfish plugin not publishing maven dependency jars to ear lib folder

I'm using the Eclipse "Internal Glassfish 3.1.2.2" server with the Eclipse Glassfish plugin (http://download.java.net/glassfish/eclipse/juno). I'm also using Maven with the m2e Eclipse plugin. The Glassfish plugin correctly deploys my EAR modules to the Internal Glassfish, but it does not deploy my dependency jars, which I believe should end up in a folder called "lib".
I found a partial solution here, which is to add my maven target lib folder to the EAR Deployment Assembly (double-click in the Deploy Path box to edit). This works, but m2e (or m2e-wtp) undoes the config change when I do Maven > Update Project.
There ought to be a cleaner solution. The Eclipse Ear Module Assembly dialog has a field to name the "EAR library directory", so it's aware of the lib folder. Where does Eclipse EAR assembly (without Maven) look for jars to put in the lib folder? I assume the Glassfish plugin is looking in the same place.
You can use the following steps to find the source of the problem:
Take Eclipse out of the equation and build EAR on command line using Maven, does it turn out ok? If not, look for a solution in your pom.xml.
If ok so far, open Eclipse and perform Maven -> Update Project. Then export EAR using Eclipse (look for EAR export wizard under File -> Export). Did the exported EAR turn out ok? If not, file a bug report for m2e-wtp plugin. It is still pretty raw, so it wouldn't be surprising if it doesn't setup Eclipse metadata correctly in some cases.
If ok so far, then it is time to look for a problem in Glassfish plugin. I doubt that you will get this far, but if you do I will help you to follow up.

Importing Java Web EE Netbeans Project to Eclipse

Looking for a clean way to export a NetBeans Java Web Project (Java EE) to Eclipse.
Already tried importing the war file, but it outputs many errors. I think because EJB object is not contained there.
Netbeans project has a connection with PostgreSQL, and Glassfish server, everything installed on my Windows PC. It's using the EJB module, and it features a REST implementation, with JPA persistance.
Using Netbeans 7.2 and Eclipse IDE 1.5 (latest)
Here is a view of the Netbeans project:
Below is the project resulted from the import of the war file (generated by Netbeans) in Eclipse.
Which would be a clean way to do this?
I can also hear ideas about importing it to IntelliJ Idea.
Solution took long, but here are the basic steps:
Create empty EAR Project In Eclipse, add 2 modules, EJB and Web Module. Then added JPA facets to the EJB project. Imported src folders. Then exported the EAR Project to to JBoss (changed Glassfish, no particular reason).
Basically 1 project in Netbeans is equivalent to 3 projects in Eclipse in this case.
Prepare to get your hands dirty.
Netbeans uses Ant build scripts by default. These scripts cannot be directly converted to work with Eclipse.
The way I did it was to create a Maven project in Netbeans and copy all source files from the Ant project to the Maven project. Eclipse provides a Maven plugin which enables you to work with Maven projects. Maven projects (if set up correctly) tend to be IDE independent.
You could try to create new project in Eclipse, and choose "Create project from existing source". Then point src folder from NetBeans project. You probably will need to organize your REST services etc by yourself, but I think that is the way.