I'm trying to build web Service using maven and eclipse. Here is steps I followed.
Generated mvn folder struture using comman prompt
mvn archetype:generate - DarchetypeArtifactId=maven-archetype-webapp
Converted the mvn project into eclipse.
mvn eclipse:eclipse -Dwtpversion=2.0
Imported the project into my workspace.
Changed the project facets such as java version, servlet version, added cxf and jaxb feature and server runtime.
Copied the WSDL to Resources folder.
Since I do not want to add dependencies(as somebody else would be doing this job for me). I added spring and CXF lib into build path. and also to deployment assembly.
Generated the jaxb classes and operations from wsdl. Here all the java classes created instead of going to src/main/java to went to src/main/resources.
I run the app on tomcat. web.xml is invoked from that cxf framework got invoked and also spring bean creation got invoked. but while creating the bean for the webservice class it threw Class not found error.
When I opened up the war I could notice that while packaging instead of placeing the class files, the eclipse placed java file as it is in the war file.
Could some one help me in fixing this problem. Not sure how to configure eclipse to compile and place .class files in the war instead of .java filee.
Figured out the problem, while importing the file eclipse is adding command, exclude all the java files from src/main/resources in srource tab of java build path On removing it worked fine
Related
I have a 2 project. One of them is maven, other one is spring project. I obtain jar file from maven project and give reference to spring project. When I call some classes and methods in compile time, it's ok. But when I started tomcat server I got a error that is "java.lang.NoClassDefFoundError" and "NoClassDefFoundError". Application does not see classes on run time.
I supposed that this error is occured cause of tomcats run time classpaths. I must add missing classes to classpaths. But how to do that ? How to handle this problem ?
IDE: Eclipse
Tomcat version: 9
Thanks for your answers. Sorry for my bad english.
you need to create jar file of your maven project and put into WEB-INF > lib of Spring project and and jar file into built path and rebuild the Spring project and run it from tomcat 9.
Try adding the jar file to Deployment Assembly. Right click on your project, click Properties, Deployment Assembly, Add your jar file and run the project on tomcat.
I'm using Eclipse 3.7 (STS) with Tomcat 7 running inside the IDE. I've created a new Dynamic Web project and added a single JSP file to the web content root folder. I can run Tomcat and access the JSP from within Eclipse with no problems.
I've added a few 3rd party JAR's to the project from User Libraries (I'm not using maven or auto dependecies managment). In the JSP I reference a class from the project's JAR file, I can compile this with no problem, but when I deploy on Tomcat the JSP throws ClassNotFoundException. Clearly, Tomcat can't find the JAR's from my library settings. I tried creating a Run As configuration for Tomcat Server and I set the classpath to match the classpath settings of the project, but I still get the same classnotfound problem.
I could get around the issue by manually copying all project JARs to the WEB-INF/lib directory so the webapp can find all dependencies, but that's absurd and I don't expect that to be the solution since it's a maintenance nightmare.
Am I missing something?
In project's properties, go to Deployment Assembly. Add there the buildpath entries as well which you've manually added as user libraries. It'll end up in /WEB-INF/lib of the deployed WAR.
You'll need to copy the jar files to the WEB-INF/lib folder: that is where they are supposed to be.
Eclipse should offer you the option of generating a WAR file that includes all the dependencies: I haven't used Web Tools for a good while but one way or another all dependencies have to be in WEB-INF/lib or the class loader won't be able to find them.
I'm using Eclipse 3.7 (STS) with Tomcat 7 running inside the IDE. I've created a new Dynamic Web project and added a single JSP file to the web content root folder. I can run Tomcat and access the JSP from within Eclipse with no problems.
I've added a few 3rd party JAR's to the project from User Libraries (I'm not using maven or auto dependecies managment). In the JSP I reference a class from the project's JAR file, I can compile this with no problem, but when I deploy on Tomcat the JSP throws ClassNotFoundException. Clearly, Tomcat can't find the JAR's from my library settings. I tried creating a Run As configuration for Tomcat Server and I set the classpath to match the classpath settings of the project, but I still get the same classnotfound problem.
I could get around the issue by manually copying all project JARs to the WEB-INF/lib directory so the webapp can find all dependencies, but that's absurd and I don't expect that to be the solution since it's a maintenance nightmare.
Am I missing something?
In project's properties, go to Deployment Assembly. Add there the buildpath entries as well which you've manually added as user libraries. It'll end up in /WEB-INF/lib of the deployed WAR.
You'll need to copy the jar files to the WEB-INF/lib folder: that is where they are supposed to be.
Eclipse should offer you the option of generating a WAR file that includes all the dependencies: I haven't used Web Tools for a good while but one way or another all dependencies have to be in WEB-INF/lib or the class loader won't be able to find them.
I have my main web application(has its own POM) that is dependent on module A((has its own POM).
When i make a build using mvn install on web application, it dependent modules
are also built in to jar file and ultimately included under WEB-INF/lib folder of main web app.
But that does not happen in when i make build using eclipse kepler (containing both maven projects i.e main web app and its dependent module A).
When building with eclipse, it just put the modified classes under moduleA/target/classes/ folder but does not make any updated jar file and put it
under WEB-INF/lib folder of main web app.
Is there a setting where i can configure eclipse building the project same way as maven does (which will really save lot of time and help in hot deployment) ?.
It used to work in one of my projects looks like some configuration is required for this.
looks like m2e connector(i have SonarQube) needs some configuration to make eclipse build in the same fashion as maven build
When i do the project > right click > mvn install , i am able to make jar file.
But what i want is eclipse build automatically option do
the build for project/module wherever modification is done , construct the jar and include it in parent WEB-INF/lib folder if it is dependent module ?
Assuming you're using the Java EE flavour of Eclipse, you can easily deploy Maven based web applications to a local server (like Tomcat, Wildfly...) from the server view.
m2e-wtp, included in recent Eclipse Java EE distros, takes care of configuring all Eclipse settings based on your project pom.xml configuration and dependencies.
See this screencast to see how simple it is : https://www.youtube.com/watch?v=TksoKkSP208
For the record, deployment/publishing is performed by each server adapter differently. They're responsible for publishing the proper jars under the WEB-INF/lib folder of the deployed application. Dependent jar projects are automatically zipped and deployed to WEB-INF/lib without user interaction
So I started with a web services project (just a dynamic web project) that builds and debugs correctly from eclipse. We've pulled a chunk of common code out that we want to put into a shared library so now those classes are going into a separate jar project that the web project references.
On the web project, I did Project->Properties->Java Build Path->Projects->Add and added the jar project. And this correctly solved all the compile-time classpath problems and everything builds fine. But at runtime, when the tomcat server fires up, spring attempts to inject some of the classes contained in the jar file and I get a NoClassDefFoundError.
My .class and properties files and the contents of my META-INF directory are showing up in the ./build directory, but my WEB-INF/lib directory seems to be referenced in-place, and the jar dependency doesn't get copied in to it to show up as part of the Web App Library.
What is the magical incantation to tell eclipse that the other jar project needs to be available to tomcat at runtime? From our ant build script, we first just build the other project into WEB-INF/lib and everything works fine, but not for eclipse debugging.
I figured this out after spending some time on it. If you are in Eclipse Helios , go to properties > deployment assembly > add > project and select the dependent project you wish to add.
Java EE module dependencies would solve this problem.
You have already done the task of extracting your common classes into its own project, possibly because other projects depend on these classes. Either way, you'll have to ensure that this is a Utility project (appears under Java EE in the project wizards), and not just a plain Java project.
One that is done, you can proceed to add the Utility project to your build path (compile-time path) as you have figured out.
The additional (final) step is to establish a Java EE module dependency between your Dynamic Web project and the shared library, which causes the utility's classes to be placed in WEB-INF\lib during deployment, and even during export of the WAR. To do so, visit the dynamic web project's properties, and browse to the Java EE module dependencies. Ensure that your utility project is selected here. Redeploy/publish your application and you should be good to go.