Eclipse's Tomcat gives a 404 while the WAR file works-previous solutions don't work - eclipse

So when I'm running my project through Eclipse's "Run on server" the 'server' doesn't work (when trying the URI http://localhost:8080/simpleapp/ there is an automated 404 Tomcat's webpage), but when compiling and deploying the WAR file through Tomcat's app manager it works fine (the exact same URI gives the response I expected).
How can I systematically solve the issue?
It's important for me to solve it since debugging is a living hell this way right now (can't do a step-by-step debugging,every time that I want to check something I have to re-deploy my project :( ).
I've looked for hours for a solution so I've tried lots of different settings, and the proposed solutions don't work here.
Specifically,when changing the server's configuration in Eclipse to 'use tomcat installation', it doesnt work through eclipse (and the WAR file cannot be undeployed and doesn't work either!),switch location doesn't work either...
More details which are optional but might help:
I have another project where the server through Eclipse does function, I've just used a different Maven archetype this time. When Eclipse's server 'worked' I used jersey-quick start-web app but this time I had to use (org.glassfish.jersey.archetypes:jersey-heroku-webapp (An archetype which contains a quick start Jersey-based web application project capable to run on Heroku)) and added dynamic web module through project facets and as I said now the Eclipse server doesn't work (oh and I've tried to delete the server and reset the configuration too, but no luck).

Try to deploy your WAR using "Add and Remove" from the Servers view instead of using "Run on Server". If the WAR doesn't appear check the Project Facets and ensure that Dynamic Web module is enabled.

Related

Tomcat and Eclipse vs Intellij

I am working with Intellij but some of my co-workers don't. When I was writing install doc, I realized that Tomcat is not managed the same way on the two IDEs.
Which is a problem considering what happened next when I tried to set up our project on Eclipse.
Basically, on Intellij, you select a Tomcat on your computer and it will literally copy the war into the webapps folder and run the server with everything working fine.
I am not a user of Eclipse so I might have misunderstood something, but I found that when you create a Tomcat server, it will embed the one you gave it to it. Doing that is a bit of an issue when you are working with logback, because usually you set your logs location directly into the Tomcat folder. And in Eclipse you are working out of this folder.
So, I can't run my application because it can't find the location of the logs folder at the fine place.
Is there a way to use Tomcat in Eclipse like Intellij? Or did I just miss something because I am kind of new with Eclipse?
See the FAQ: (1) (2)
I found that when you create a Tomcat server, it will embed the one you gave it to it.
You have to be more specific with your description. How you do things and what do you see. What do you mean by "embed"? What is the actual failure that you are observing with your logging?
There are different ways to do things.
For me by default Eclipse does not embed Tomcat, but runs it as a proper java process. (org.apache.catalina.startup.Bootstrap) You should be able to see it with jconsole and similar tools.
It runs your web application expanded, i.e. without zipping it into a war file. It creates a separate configuration of Tomcat, i.e. runs it with separate CATALINA_HOME and CATALINA_BASE directories (as documented in RUNNING.txt file of Apache Tomcat). The CATALINA_HOME directory stays untouched and CATALINA_BASE directory is ${workspace}/.metadata/.plugins/org.eclipse.wst.server.core/tmp0 etc. A logs directory can be found there.
One known caveat is that java.util.logging is not configured by default (the system properties java.util.logging.manager and others are not set). See "How do I enable the JULI logging" item in the FAQ. -- In the same way you will set any other system properties that you may need.
The default configuration of java.util.logging (as provided by JRE) is to log everything to the console, without creating any files.

Unable to deploy my spring web project to eclipse internal tomcat server.(java.lang.ClassNotFoundException on tomcat startup)

when I use an external tomcat everything is just fine. but I need to deploy my project on internal eclipse tomcat server in order to be able to use DCEVM class hot swapping.
When I try to start tomcat server from within eclipse it says it is not able to find one of my service classes I mentioned in my spring security configuration file as a bean.
I also tried to add the project to tomcat class path but it did not solve my problem.
UPDATE
I found out the problem is because when I deploy my web project to eclipse tomcat server, no .class is copied to:
C:\Users\Meysam\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\villapweb\WEB-INF\classes
in fact, this folder contains my src/java/main package structure but no .class is copied in it.
lib folder is fine though (e.g. all dependencies of maven and other stuff copies in the path it is supposed to)
I think there might be something wrong with m2e-wtp plugin. I dont know what!
I am using eclipse 4.3 BTW.
SOLVED
I Solved this issue following these steps:
right click on project in eclipse > properties > project facets
in the right panel select runtimes and select your target server. Apply and ok.
in the server modules list right click on project module and click clean module work directory
right click on the server itself and you can clean both server and tomcat work directory one after another
if that didn't work, try project > clean and also toggle "build automatically" option under project menu item.
Thats it. tomcat now copies all .class files to the target server and you see no ClassNotFound exception as tomcat starts up.
[Copied to answer section]
I Solved this issue following these steps:
right click on project in eclipse > properties > project facets
in the right panel select runtimes and select your target server. Apply
and ok.
in the server modules list
right click on project module and
click clean module work directory right click on the server itself
and you can clean both server and tomcat work directory one after
another
if that didn't work, try project > clean and also toggle
"build automatically" option under project
Thats it. tomcat now copies all .class files to the target server and you see no ClassNotFound exception as tomcat starts up.
I've followed the steps on the answer but It still wouldn't work for me, so, besides doing these steps once, I've found that doing a refresh on the target after doing a clean install automatically triggers the "Republish" status on the server, so when the server is executed all changes on the compiled classes (new classes and changes to existing ones) are then copied to wtpwebapps when the server is started.
I had almost the same problem - one of my projects did not make it to the deployment area (its jar). What i did is 1) remove the appliction from tomcat 2) clean tomcat work directory 3) most important: project - clean - all. Then i added the application again and... problem solved
I had the same problem in Web Dynamic project converted to Maven project.
I found error in properties->Deployment Assembly->right panel.
There was source=src folder and deploy path=WEB-INF/classes. Classes couldn't be found by Eclipse.
Changed to source=target/classes.

Running PlayN in HTML DevMode

I'd like to be able to run my PlayN project as a Web Application in DevMode, so that I can use a quick browser refresh to see code changes without having to recompile. From what I'm reading on the wiki and on this question it sounds like that should be possible.
I set up my project using: mvn archetype:generate -DarchetypeGroupId=com.googlecode.playn -DarchetypeArtifactId=playn-archetype -DarchetypeVersion=1.7 and importing the pom.xml into eclipse.
Here's what I can do:
Run from eclipse as a Java Application
Start the server using Maven command line: mvn -Phtml integration-test
While I can do most of my programming in Java and occasionally do the long build to test HTML, I'd love to be able to modify the code while testing HTML without recompiling.
By default, the option to run as a Web Application doesn't show up. I've tried going into the project's properties and checking the "Use Google App Engine" and "Use Google Web Toolkit" options, which creates the "Run As Web Application" option, but when I do so I get "Could not find any host pages in project XXX".
I then attempt to set a WAR directory under Properties->Google-Web Application. However, the closest thing to a WAR in the project is "src/main/webapp". I've tried using that, and I get the error: "The archive: /myproject-assets/src/main/java which is referenced by the classpath, does not exist."
I have the feeling I'm going about this all wrong. Can anyone point me in the right direction? Is what I'm doing even supposed to be possible? Thanks!
It is possible, but just know that in dev mode, playn runs very slow.
I don't know how to do this with eclipse, but with intelli IDEA, you do the following:
you need to create a module with a war artifact (to run as a server)
add the correct gwt libraries so that you can run gwt dev mode server with the aforementioned war module.
choose a GAE server (or, any gwt compatible server actually, this will be the server that runs the aformentioned war module).
run it! see this screenshot http://screencast.com/t/qK4JKvF33V
when you change code, the gwt devmode server should detect it, and automatically recompile (not sure if this needs to be in debug mode - i don't think it does).
you can try doing it via the command line, not sure if works, but this is what intellij runs (i've taken out the intellij specific bits out):
java -cp CLASSPATH_WITH_GAE_DEV_TOOLS_AND_GWT_DEV_TOOLS com.google.gwt.dev.DevMode
-war /path/to/war
-startupUrl Roborally.html com.yourgame.YourGwtEntryModule
-server com.google.appengine.tools.development.gwt.AppEngineLauncher

debug GWT on tomcat using eclipse

I'm using GWT 2.4 and have a ton of code already written. I understand the Jetty server that comes with the GWT plugin has very tight control over the jars that can be used in a project to mimic app engine as closely as possible. I need to deploy to tomcat 7. I modified my project in eclipse and "blessed" it as a dynamic web project so I can export...WAR and upload it to my QA and production tomcat.
I need help with getting the app to run (and debug) on an embedded tomcat (like an honest dynamic web project would). I already have tomcat setup in eclipse and I have my CAS server web app deployed to it.
I've ready tons of either old or confusing posts here and elsewhere. Basically, I'm looking for the same debugging environment I would get with the packaged Jetty server, but on my own tomcat configured with WTP in eclipse...so I can mimic my production environment (just like Jetty mimics app engine)
any help is appreciated.
It should probably a little bit easier, but it's possible. Here's how I do it:
1. Setting up the web server
Using the JavaEE edition of Eclipse, I set up the Tomcat 7.0 server adapter, and define an environment in Preferences > Server > Runtime Environments
File > New > Project... > Web/Dynamic Web Project
Select the target runtime I set up in the first step
Important: In Context Root, enter /
I create an HTML file and a Servlet, and then try running the setup using Debug As > Debug On Server
2. Adding the GWT code server
Project > Properties > Google > Web Toolkit > Use Google Web Toolkit
Important: I always need to change the order in the Java Build Path (Project > Properties > Java Build Path > Order and Export), see http://code.google.com/p/google-web-toolkit/issues/detail?id=4479 - gwt-dev.jar must be pretty much on top of the path.
Project > Properties > Google > Web Application: War directory = "WebContent", also check "Launch and deploy from this directory"
I create some sample GWT content (I create a sample GWT project, and copy most of it over)
I try to GWT compile the project. This shows me, if I got the build path order right - otherwise, the compiler fails early with "java.lang.NoSuchFieldError: warningThreshold".
Debug As > Web Application - just to create a debug configuration. Stop the debug. Edit the debug configuration (Run > Debug Configurations...), deselect "Run built-in server". Start the debug again.
Now, finally, I can debug both the server and the client part (I still need to click two Debug icons to start both!) I can manage the client side from the "Development Mode" view, and the server side from the "Servers" view. At the end of the day, it works great, and using the "Automatically publish when resources change" feature (Servers view > myServerName > Open > Publishing), sometimes even better than with the integrated Jetty.
At first thought, I don't really see why you would be facing a problem. Perhaps, the way Eclipse is laid out is too confusing and daunting.
On my Eclipse, I had been using the default jetty as the server during GWT debug. However, there were some problems which would not be caught by jetty when deployed on Tomcat or JBoss.
And when I added Tomcat or JBoss instances to Eclipse and added my app to those server instances, the debugging worked straight away. Are you missing one piece of vital, but simple info?
Let me presume that the following would fill in your missing link ...
Locating/adding your server instance:
On Package Explorer (or Project Explorer, either one) in Eclipse, you would see, besides your personal projects, a "servers" project. Under it is are configuration nodes listing all your Tomcat instances.
If you cannot see the "servers" node in Package Explorer, it probably is due to your working set filter. (And if you don't know what working sets are ... I guess you would need to beef up on your dexterity in Eclipse).
If you don't already have a Tomcat instance, you simply right click on the "servers" project to add a new server (Package Explorer -> New -> Server ...). You would be asked the location of your Tomcat home. And your desired port number of the server instance. Of course, you would have to ensure that the port number will not clash with the port used by any other inet operation on your box.
Configuring the port number a 2nd time
On the server instance node in Package Explorer, you would find the file you should edit to set the port number to match the one you specified when creating the new Tomcat instance. If you don't know which file to edit, you would need to read up on the Tomcat version you created to find out which file contains the port number config.
You need to config the port a 2nd time because the 1st time tells Eclipse where and at what port to expect the server instance to be running. The 2nd time is to configure the server instance itself.
Adding your app to the server
However, the nodes in "servers" project only allow you to configure your Tomcat instances. There is yet another view called the "server view" to further configure your tomcat instance. You need to enable Server view from Window->Show View->Server->Servers.
Right click on the server instance in the "Server View" to add your app.
Running debug off the Maven generated target.
There are times you wish to debug the war structure to figure out which jars are missing in the war. And incrementally remove jars from your war to figure out the jars that are already supplied by the server. Since JBoss supplies many of the jars already, you would have to figure out if your development jars are of the versions as those expected by JBoss.
You would create another Eclipse project in your workspace and make an Eclipse folder softlink in your 2nd project to point to the Maven generated target of your first project. And you specify target/{maven generated webapp directory} as the webapp directory of your 2nd project. What I mean by "maven generated webapp directory" is the unzipped intermediate directory generated by Maven (used by Maven to generate the zipped war file).
This is the cleanest way to debug production war if you could faithfully replicate the production tomcat/jboss server on your Eclipse development box.
If you prefer JBoss.
Somehow, JBoss config node is not listed in the "Servers" node in Package/Project Explorers. You would need to go to your JBoss installation directory to edit them.
Remote debugging.
If you wanted to debug the app on your production box, or on a server sitting on another box, you would have to start that tomcat instance under debug. You should read up on that. You have to specify the debug port.
Then in Eclipse, at Run->Debug Configuration->Remote Java Application, you specify the app and the debug port.
The first time you debug, Eclipse "may not know" where the source files are, especially if your app has multiple project dependencies. (Why can't Eclipse search the source files from my list of projects?) Anyway, you have to specify where to find your source files. And then when your debugging traverses into another project dependency, you would have to over-write the location of the source files.
So, voila! That is how I got my debugging working. I advise you to avoid remote debugging as much as possible unless you need to diagnose production problems. Unless you are doing remote debugging, do not attempt to deploy the war to local server, but simply depend on associating the project to the server instance.
Eclipse is too confusing
I know Eclipse is too confusing and you have to wade thro its features. You just have to bear with it. Eclipse menus & views are apparently optimized for plugin-programmer-centric not user-centric.
For example, why would I go to "help" to install new software? I used to expect that "Help->Install new software" to be an instructional manual to installing new software.
It beats (and annoys me) that the Eclipse team did not combine the operations together so that I could add apps to a server instance at Package Explorer. Why not? As a user I would expect to see only a single entry point to configuring my servers.
To alleviate the confusion, I like encouraging people to download and install Springsource's version of Eclipse (STS). It's the same Eclipse, except that STS has the essential parts installed and has a dashboard pointing to compatibly installable plugins. Tomcat is preinstalled as VMware tc Server. And the views are correctly config'd to show the server instances. And the correct workable Eclipse-Maven bridging plugin is pre-installed.

Efficient dev cycle with Maven, Tomcat/Glassfish, Archetype?

So far i've been using tomcat and glassfish to develop a testing webapp, without maven. And the usual development-till-deploy cycle is simple :
develop in eclipse ide, with a WebContent folder, which is the root webapp folder that has the WEB-INF, web.xml, WEB-INF/lib, n all. The compiled classes location in eclipse is set to WEB-INF/classes.
after coding, i could just click on the reload button in glassfish admin console for that specific webapp. In tomcat, i believe it's reload also in the tomcat manager.
i could access the web application in the browser
Now if i would like to create a new webapp, that'll make use of latest stuffs of jsf, spring, jpa, hibernate, postgresql :
what recommendation of archetype should i use in the creation of the project ?
can i still use my previous steps of development? because i think it's very easy without having to repackage everything into a war file, or copying it into the tomcat's webapp folder everytime i want to test. Saving the files in eclipse, hit on the reload in the admin console / tomcat manager, and i could instantly test the updated webapp.
Or what do you usually do in the webapp development cycle ? Please share your experiences, =)
Thank you !
Development Cycle with Maven and Friends
Use Maven to drive your code-build-test-deploy-release cycle.
Start with Maven Archetype that suits closest to your web-app. This will create the whole folder structure for you and will add Jar depencies.
Use an embeded light-weight server like Jetty, this will be very fast on dev machine without sucking resources and is highly configurable. Plus, you can set it to auto-reload changes.
Most of Maven project are supposed to be test-driven. Of which Maven takes care of using it's surefire plug-in. So, every build will have a test phase.
You can define multiple profile for various environments (test, dev, prod, Win, Unix..). These profile will alter the behaviour of the project to be compatible with the environment.
Use Cargo, again a Maven plugin to deploy your builds on test or production server, which can be Glassfish, Tomcat, Jetty or any oter webserver.
Use Liquibase with or without Maven :) to manage your database changes the same way you manage your code change.
I came from almost similar project as yours in my previous company. Development with Maven makes things so smooth and the change is appreciable.
A little Google search shows that someone has worked on archetypes for JSF and JPA with Spring
Edit#1 -- added more details
Feasibility and Ease of Use
Maven is born out of neccessity to simplify the dev process for large and distributed code.
Maven is very well integrated with Eclipse -- so it's painless.
Jetty keeps monitoring source folders, so your changes gets deployed almost immediately.
You can customize the build to skip tests, to not build dependecies. When you just edit a UI component, Jetty will silently copy it to "target" folder.
If you're worried about copying and redeploying. You must read THIS to see how efficiently things are done, keeping in mind that you don't have to compile-test-deploy everytime you change a JSP or HTML.
That said, I would like to mention that Maven might be a challanging learning. This is an object oriented way of development cycle, to say. Most of us, who are used to build script, can find a bit tedious/verbose initially.
Resources
I would suggest to go through the following resources
Maven Book - Maven basics
Automated Deployment with Maven - going the whole nine yards If you can, literally follow this pattern.
Maven 2 Effective Implementation -- this book really helped us a lot.
for the q2 :
You can still run/debug app with tomcat from within the IDE (eclipse) even if you change the directory structure. (like the maven dir structure instead of eclipse's dynamic web dir structure)
Project properties - >
project facets - >
Dynamic Web Module ->
Click the appearing "further configuration available"
and set your content dir and context root.
You dont have to package everytime you want to run/debug it.
Another option is using Jetty
And I am sure there are more options others will tell as well.