Eclipse - Make dynamic web application include other projects in workspace - eclipse

I'd like the exported .war file to include the other (referenced) projects in the workspace.
When I reference them in the Build Path only, it shows no "Problems", but ClassNotFoundException is thrown later, when I try to "Run on Server" or export.
Using eclipse Kepler, tomcat 7.0.42.
I've seen the solution here: Not able to configure run path for web application project in Eclipse workspace; that's how it works now. Is there a more convenient way?

Are you running Tomcat within Eclipse? Try this:
Run -> Run Configurations... (or Debug Configurations...).
Find Tomcat v7.0 Server at localhost (or whatever it's named for you) under Apache Tomcat on the left-hand side.
Go to the Classpath tab on the right.
Select User Entries and click Add Projects....
Select the projects you wish to include.
That should place that project on Tomcat's classpath.

Related

How to start apache tomcat packaged within eclipse?

My company does not allow me to upload apache tomcat from the official website . They told me that I already have it as a "plug in " in Eclipse . It's sort of packaged . So , anyway I could not find a startup.bat file anywhere .
I have the following folder on my computer that presumably contains apache tomcat somehow installed there. I am not sure whether i have a jboss . Here is the folder
If I go to the jre folder there is a servertool.exe . It looks like this
I am not sure how I can start apache tomcat . I mean I am not allowed to upload the zip file directly form the website, otherwise I could have used the startup.bat . . . I have never encountered a situation like this . I do not have a regular apache tomcat folder .
I tried localhost:8080 no result
How can I start working with it ?
Thanks
Eclipse does not ship with Tomcat. It integrates very nicely with it, though, after you install Tomcat. These instructions are for Eclipse Kepler SR1; other Eclipse versions are similar. There are third-party plugins that do this too, but the native plugin works nicely. Also, I'm not sure, but pretty sure, that you need the "Java EE IDE" version of Eclipse, not just regular Eclipse for Java. The steps:
1) Install Tomcat from the ZIP file (which just means extracting the ZIP to somewhere like c:\tomcat)
2) In Eclipse, choose Preferences from the Window menu; in the search box, type "runtime", then click Runtime Environments under the Server category (if you don't see this, you may not be running Eclipse Java EE; again, not sure if "regular" Eclipse for Java is enough).
3) Click the "Add" button and go through the process of telling Eclipse about where your Tomcat server is (i.e., it's where you just installed it to).
4) Create a Dynamic Web Project for your web-app (regular Java projects won't work; if your code is already in a regular project, migrate it into a Dynamic Web Project).
5) From the Window menu, choose Show View, then Other, then type "servers" and double-click Servers.
6) In The Servers pane, right-click anywhere in the pane and choose New, then Server. Follow the instructions to create a new Server that uses the Tomcat runtime you just created in Eclipse. When you're done, you'll have a Tomcat server listed in the Servers pane.
7) Not it's time to add your Dynamic Web Project to the list of web-apps that this server (that is, this Tomcat) knows about. So, right-click on your Tomcat server in the Servers pane, and choose Add and Remove. In the dialog that opens up, click Add All, then Finish.
8) Start Tomcat by clicking the Debug icon above the Servers pane (it looks like a green bug). Load http://localhost:8080/ (or http://localhost:8080/yourappname depending on your config) and you're done. (You can also run Tomcat by clicking the Run icon -- instead of Debug -- but one of the big reasons to run Tomcat from within Eclipse is that you get to use Eclipse's debugging functionality.)

Change eclipse's built in tomcat context.xml file using WTP?

Is it possible somehow to modify the contents of the context.xml that eclipse uses when you are doing "Run as" -> "On server"... and "Debug as" -> "on server"
We have some settings that are in our production environments context.xml file and we need them to be available to eclipse built in tomcat as well.
I know we could use eclipse to run run on an external server, but thats not as convenient.
Have a look at the automatically created project "Servers". There should be a folder for each configured Server. There, open the context.xml and add anything you like to be in the "default" context (Parameter-Tags for example).
Anything that's inside there will be used to populate the context.xml WTP automatically creates on publishing for each project on that Server.
Or use the project specific way: put a context.xml with your contents inside META-INF in your project (have a look here: http://wiki.eclipse.org/WTP_Tomcat_FAQ#How_do_I_specify_the_Tomcat_context_configuration_for_my_Web_Application.3F)

Eclipse: How do I add the javax.servlet package to a project? [duplicate]

This question already has answers here:
How do I import the javax.servlet / jakarta.servlet API in my Eclipse project?
(16 answers)
Closed 7 years ago.
I'm using Eclipse 3.6 Helios (for Java Developers) and want to add the javax.servlet package to one of my projects.
What do I need to configure/download?
To expound on darioo's answer with a concrete example. Tomcat 7 installed using homebrew on OS X, using Eclipse:
Right click your project folder, select Properties at the bottom of the context menu.
Select "Java Build Path"
Click Libraries" tab
Click "Add Library..." button on right (about halfway down)
Select "Server Runtime" click "Next"
Select your Tomcat version from the list
Click Finish
What? No Tomcat version is listed even though you have it installed via homebrew??
Switch to the Java EE perspective (top right)
In the "Window" menu select "Show View" -> "Servers"
In the Servers tab (typically at bottom) right click and select "New > Server"
Add the path to the homebrew tomcat installation in the dialog/wizard (something like: /usr/local/Cellar/tomcat/7.0.14/libexec)
Right click on your project -> properties -> build path. Add to your build path jar file(s) that have the javax.servlet implemenation. Ite depends on your servlet container or application server what file(s) you need to include, so search for that information.
When you define a server in server view, then it will create you a server runtime library with server libs (including servlet api), that can be assigned to your project. However, then everybody that uses your project, need to create the same type of runtime in his/her eclipse workspace even for compiling.
If you directly download the servlet api jar, than it could lead to problems, since it will be included into the artifacts of your projects, but will be also present in servlet container.
In Maven it is much nicer, since you can define the servlet api interfaces as a "provided" dependency, that means it is present in the "to be production" environment.
Go to
JBoss\jboss-eap-6.1\modules\system\layers\base\javax\servlet\api\main
include JAR
jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar
For me it worked
For me doesnt put jars to lib directory and set to Build path enought.
The right thing was add it to Deployment Assembly.
Original asnwer
Download the file from http://www.java2s.com/Code/Jar/STUVWXYZ/Downloadjavaxservletjar.htm
Make a folder ("lib") inside the project folder and move that jar file to there.
In Eclipse, right click on project > BuildPath > Configure BuildPath > Libraries > Add External Jar
Thats all

Eclipse publishing to Tomcat

I recently came back to using Eclipse after 2 years of IntelliJ. Things have changed.
Now when I try to run Tomcat, it tries to publish my project to it. What the hell is publish?
What ever happened to pushing a war into the webapps directory and letting Tomcat deploy it?
Right now my deployment is broken because of compilation errors. I have a feeling that Eclipse is taking my project and copying it to webapps dir without first building it properly.
Can someone explain to me what exactly publishing does, and also how to turn it off and use Tomcat like normal people?
A the "Servers" view, you can double click on your Tomcat instance, to open the server settings editor.
There, at the upper right corner, you can find the Publishing options. Check the "Never publish automatically" option, and save.
With this it should be enough.
Oh, and by "Publishing", they kind of mean "Deploying", or "Copying to the deploy directory", depending on what server you are using.
Eclipse (Helios) makes a copy of your entire Tomcat configuration and starts a new instance of the Tomcat server when you are running the web application from Eclipse. That is why you must shut down any existing Tomcat service before running in Eclipse.
The application runs out of your workspace, not out of the "webapps" folder. Eclipse modifies the copied server.xml file to add "CONTEXT" tags that include your workspace project folders in the running application list.
The path in the "CONTEXT" tag should be the name of your project folder.
You can export the project to a WAR file and deploy your web application to the webapps folder if you want.

How can I add my application to Tomcat in Eclipse?

I have a web app built with Maven.
Most of the time, I built the application using Intellij IDEA, but now I want to import the application in Eclipse to see something in this IDE.
After mvn eclipse:eclipse, I add in Eclipse the app, but when I try to add the app to the server (tomcat), I receive:
There are no resources that can be added or removed from the server
Solutions?
You need the project to have a Eclipse Dynamic Web Module facet. You can try doing this via the project properties dialog and looking at project facets, then clicking the appropriate check box. This may not be available however, so you may need to do the next thing.
Create a backup of your project and follow the directions at dzone.com. This'll allow you to modify the project facets via your eclipse .project file.
Keep in mind, once you add those facets, you cannot change them back via Eclipse. Definitely make sure you have a backup before starting.
This step worked for me:
Right-Click on the Project Name, then
Maven-->Update Project..
Click OK
After doing this I was able to see my project in Add/Remove Programs.
As mentioned somewhere else adding Eclipse WTP didn't do any good, however I performed the above step after I had already added Eclipse WTP, so I am guessing that may not be needed.
This was done for Eclipse Juno.
Hope this helps someone.
Edited: You can follow this link as above mentioned I think might have needed WTP and that add a lot of other things into the workspace.
http://blog.teamextension.com/maven-as-eclipse-dynamic-web-module-556
Check whether Maven Integration for Eclipse WTP is installed. If not, install it from Eclipse Marketplace
After installation restart Eclipse
Right click your project and Maven--> update project configuration
Delete tomcat and re create tomcat (clean tomcat,add your project,publish and enjoy)
I've got Tomcat 6, Java 1.6, and was trying to get it to work in Eclipse Juno Service Release 1's "internal server" (whatever that's called.) Here's what I did that worked for me:
(Found these instructions at http://www.mkyong.com/eclipse/eclipse-ide-tomcat-version-6-0-only-supports-j2ee-1-2-1-3-1-4-and-java-ee-5-web-modules/)
I should point out that I followed ClutchDude's instructions to make my project a Dynamic Web Module facet. It didn't work on its own for me, but maybe it was part of making it work in the end.
Using Eclipse (or other text editor), open the file
.settings/org.eclipse.wst.common.project.facet.core.xml
Find the line that reads
<installed facet="jst.web" version="3.0"/>
3.0 is for Tomcat 7.x (so says mkyong.) Change it to 2.5 (or 2.4).
I restarted Eclipse and it worked for my project.
The reason why this is happening is because eclipse by default looks for the deployment descriptor in the folder {project.home}/Webcontent/WEB-INF/web.xml where as the Maven puts them in src/main/webapp/WEB-INF/web.xml.
So when you are trying to add your project onto the server eclipse cannot find a deployment descriptor and hence you get the annoying message.
This can be solved by adding the following entries in .settings/org.eclipse.wst.common which can be found in
Project home folder in your workspace if it is a new maven project.
The folder where you already imported from if you are using Import -> Maven projects.
Make the following changes in to the org.eclipse.wst.common
wb-resource deploy-path="/" source-path="/src/main/webapp"/. Add this entry.
Edit --> property name="java-output-path"
Please check the following link from more details. http://java.dzone.com/articles/webapps-eclipse-and-maven.
The comments section has an excellent example with a working project.
This issue was fixed for me my installing additional eclipse modules. in particular, the ones related to m2e-wtp. just do a search for m2e in the plugins search listing for your version of eclipse
If you face an error like "There are no resources that can be added or removed from the server",
then
1) Go to the META_INF of your websvcsEAR and go to the application.xml.
2) Goto modules-> clickDetails and add the module that is existing. i.e., some EAR which your project demands.
3) Click ok
4) Now go to your server -> right click -> add and remove -> add your EAR.
Maybe you don't need add your application to the server's configuration. I think that you must use m2e eclipse plugin in order to launch the app.
For example, in your eclipse you will see a contextual menu called "Run as" if you right-click on your pom file. You can clicking on "Maven build" and Maven will download all the information needed to start tomcat.
I hope this helps you.
I used
mvn eclipse:eclipse -Dwtpversion=2.0
in command line in the folder where I had my pom.xml. Then I refreshed the project in eclipse IDE. After that I was able to add my project.
I was able to resolve this by removing my EAR project from my Eclipse workspace, then re-importing it.
Well, with a Spring and maven project, i got it that way:
Eclipse Version: 2019-06 (4.12.0)
Java 1.8
Tomcat 7
Yes, go to Project Properties >> Facets >> select Dynamic Web Module but dont apply yet!!!
Right under, it should appear a link Further Configuration Available. Click on it, otherwise one will have to edit .settings/org.eclipse.wst.common.component manually. Update source directory to src/main/java. (source)
Then in Facets window check Java - mine was pointing to 11 even though i don't have Java 11 installed or configured like a JRE runtime. I could only add/remove when changed to 1.8. (source). Note: That was really the problem, why don't Eclipse get this configuration automatically from the project?
Finally Eclipse creates some directories like WEB-INF and META-INF, just delete them.