tomcat7 web servlet wouldn't work - eclipse

So I'm using eclipse and wrote 2 separate project. My servlet project is using the JAR file from the other project and it runs fine on the tomcat server built in to eclipse. However, if I package the servlet project into a WAR file and deploy it on the tomcat7 directly on my machine (not through eclipse), then it wouldn't run. I'm worried it might be some problem with the classpath. When I ran in eclipse, I had to manually went in RunConfiguration and add those jar files into the tomcat server classpath. How would I do that through command line?

You shouldn't mess with the tomcat classpath. Put the jar in the WEB-INF/lib directory of your war, as all the other libraries that your webapp uses.

Related

WAR file build in tomcat project

I have a traditional tomcat project configured in eclipse. I could run it successfully through eclipse by providing the tomcat configuration like below,
Window->Preferences->Tomcat
Provided the Tomcat home and configuration file tomcat server.xml file.
In server.xml file i have provided the context declaration details to access the application.
Now, i would like to build the WAR file for this project using eclipse or ANT. When i try to export the WAR file using eclipse, the module name for the project is not captured.
Could anyone please give me the suggestion to build the tomcat deployable WAR file for Eclipse->Tomcat project.
Thanks in advance..,

Deploy IVY resolved war file to eclipse tomcat?

I am trying to understand whether it is possible to have an eclipse tomcat runtime configuration that will publish the IVY resolved war files when tomcat is started?
I have created a tomcat server instance in eclipse and pointed it at a catalina configuration which includes a server.xml that specifies the contexts. For example.
<Context docBase="Module1" path="/Module1"/>
Module1 is a resolved war file and I have added the corresponding ivy.xml file to the eclipse tomcat classpath. I can see the war file has been resolved, but I assume I must have to do something extra to get the war files auto deployed on server startup?

Deploying an EJB .jar to jBoss/WildFly from Eclipse

I am new to Java EE. I use Eclipse, jBoss/WildFly and Maven. I have a multi module Maven project:
parent Maven project (pom)
web application (war)
EJB project (jar)
Currently, the EJB jar project is packaged inside the web application and the entire solution is deployed as one war file.
I want to change it: I need to deploy the war and the jar projects to the application server independently (as two independent applications). Then the web project could access the EJBs via their remote interfaces.
The problem:
I can deploy the war project in Eclipse with the Run As > Run On Server context menu, however when I attempt to deploy the jar project in the same way, I get an error message saying that the project cannot be deployed.
How can I deploy my projects independently from Eclipse?
Should I wrap the jar project into an ear project? If so, can I convert my jar project into an ear project, or do I have to keep my jar project and create one more project to wrap it into an ear? (I would no like to introduce one more project).
Look at your packaging for your EJB project. You should have
<packaging>ejb</packaging>
This will allow you to run the EJB project on the server.

Netbeans Maven project to IDEA 12

Short version: I would like to deploy Maven generated WAR to Local Tomcat server and not to build the war with internal IDEA process since the produced WAR file is not the same as the Maven generated one.
Long version: I have been using the Netbeans IDE for my Maven Java project. One of the modules is packaged as a WAR and should be deployed to tomcat server.
In Netbeans when I selected "Run" on the Web Module it asks for application server configuration then it runs the maven 'package' goal and deploys the application(generated WAR) to the Tomcat Server probably via Tomcat manager. So far so good.
We are now in the process of switching to Scala language. Scala classes extend old Java classes and the project is now "Mixed". I have configured Maven to compile the project as a mix of scala and java code. Maven produces a WAR which can then be deployed to Tomcat server without trouble - everything works as it should.
Now I would like to switch to Intellij-idea 12 IDE. But I have a problem: IDEA is refusing to deploy Maven created artifacts and insists of building one by it's own. The war is not the same and can't be used. Is there a way to tell IDEA to use Maven generated WARs and not try to make it's own ?
Just for the record I have already read these articles:
http://riddhimandas.com/blog/111
http://www.jetbrains.com/idea/webhelp/configuring-web-application-deployment.html Manually build WAR by IDEA - Want the maven generated one
IntelliJ IDEA: Maven, project compilation and deployment There is a hint here that IDEA can deploy Maven artifact from the 'target' directory but there is no information on how to do that.
With the help of CrazyCoder I figured it out.
You can make Intellij-Idea to upload your war by selecting External Source
But that's not all, even if you have a context.xml file difining your Context Root inside your WAR file: http://docs.oracle.com/javaee/1.4/tutorial/doc/WebApp3.html
You must specify one for every artifact you deploying (Unless someone will correct me)
The before launch section can be used to tell Idea what to Maven Goal to Run if any

Import and run WAR on eclipse

I have a subproject in a Virtual Machine with Ubuntu which I compile with Maven and then run with mvn jetty:run.
Maven also packages it as a war.
All of this works fine and does what is expected.
I am trying to import this WAR from another eclipse in Windows so I have done it by Import -> WAR, thus creating a Web application.
I now want to run it from Eclipse so I have created a new Jetty Server and run my application as Run on Server but I am getting Could not find the main class.
What is the proper way of doing this?
Besides, I have tried deploying the application by putting it in the webapps Tomcat directory . I can see it in the Tomcat GUI and launches the index.html but when I tried to access some of the services it throws No service was found
When deploying, in the Tomcat console I can see runtime NoClassDefFoundErrors.
Is there anything that mvn jetty:run does that the tomcat regular deployment does not? How is it possible that this didn't happen in my Virtual Machine? Shouldn't those classes be all in the WAR?
EDIT:
Here is another hint. When I run the project imported from the WAR in the Ubuntu VM, either with Jetty from eclipse or adding it to the webapps folder it works fine.
It is only hen running it on Windows Host Environment when it fails.
The specific NoClassdefFoundErrors thrown on cmd is the following:
Caused by: java.lang.NoClassDefFoundError: org/ow2/frascati/explorer/
api/FraSCAtiExplorer
That is one of the modules fo the main project.
If you try to deploy your war in tomcat's webapps folder, and if you miss a class, then you probably miss a jar in your lib folder. It is probably a jar that is supposed to be provided by the web server.
We need to know which class is missing.
Finally all errors have been solved by doing the following:
First I recompiled the WAR which did work this time under Jetty in Windows cmd. I apologize as this must be due to some error I still don't know, probably sharing the wrong WAR with Windows HOST OS from the beginning.
On the other hand, the Eclipse was solved by moving the Jetty folder out of the "Program Files" directory. It seems the old Jetty 6 adapter Eclipse comes with does not recognize spaces in its route to the server.