I have a problem providing some third party librarys (JAR-files) I am using when deploying my dynamic web application with Tomcat 6 and Eclipse.
Please note that I -do know- how to do this in a setup, where the web application project -directly- depends on those JARs.
However, in my setup, I have two Eclipse projects:
core is a class library and depends on, lets say, a.jar.
web is the web application and depends on core.
In the project settings of web, in the Deployment Assembly category, I have added core, so Eclipse (or Tomcat - I'm not quite sure who the responsible actor here is) is putting core.jar into the libs directory of my web application.
The problem is: When I try out the web application, a NoClassDefFoundError is thrown when core accesses classes from a.jar. What am I supposed to do about this? I don't think that putting a.jar into the Deployment Assembly settings page of my web application is the right solution, since it should be of no relevance to the web project, what the core project depends on.
Basically, I am looking for a way to configure Eclipse (Tomcat?) to 'embed' the dependencies of core into core.jar. The problem about this is, that core.jar is generated automatically, when I deploy my web project.
Help is very appreciated.
Thanks in advance!
Well, I've found the answer on my own meanwhile.
For those reading this in the future I will explain step by step, using the semantics I introduced in my original message:
First, open the properties page of your core project and navigate to the 'Libraries' tab of the 'Java Build Path' settings:
Make sure to add your class library a.jar, your core project depends on, via 'Add JARs...'. Then, go ahead to the 'Order and Export' tab and activate the just added a.jar for exporting.
Then go to the 'Deployment Assembly' settings and also add a.jar here by first clicking on 'Add...', then on 'Java Build Path Entries' and finally selecting a.jar. Make sure to enter '../' as the deploy path for a.jar:
Now you are done with your core project. Now open the 'Projects' page of the 'Java Build Path' settings for your web project and add your core project by clicking on 'Add...':
Finally, navigate to the 'Deployment Assembly' settings page, press 'Add...', then take 'Project' and select your core project on the next screen:
You're done. No need to add your core dependencies to your web project.
As far as I know eclipse doesn't do it for you. Project dependencies are for compile time. Runtime dependencies that span across projects should be handled by you. One trick you can use to create user libraries. Go to preferences -> Java -> Build Path -> User libraries. Create a new user library. Add all the jars that your 'core' project depends on. Add it as a dependency to both 'core' and 'web' projects. To do that,, right click on project -> Build Path -> Configure build path -> Libraries tab -> Add Library...
Hope this helps
I suggest using Maven which will automatically compiles the jar files for you and Eclipse works with Maven very well too.
If you have a Gradle-Project make sure, you have the "eclipse-wtp" Plugin in your build.gradle's of the Sub-Projects.
Related
I have a Maven based desktop App and I have to convert it to a dynamic web app in eclipse or any other IDE ( I am using Eclipse Neon-Java EE).
I have tried with Project Facets (Right click on project name --> Properties --> Project Facets --> dynamic web app) It generates some files but it doesn't seem to be converted to web as in the project folder still appears the letter "M" and not the golobe icon. When I try to run it in Tomcat it doesn't work.
Project Folder
Any suggestion?
Thank you
Look into the project if you have the Maven convert option...
If not, you should check the property of the project, and change them manually, starting from the Deployment Assembly, the target runtime, check all the facets..
Then take a look into the folder of the project, into .classpath and .project and see if they have been refreshed by Eclipse, the pom should package as a war and so on...
The problem here is that you are fighting with Maven and Eclipse togheter, so my main suggestion to do this in lees time, is to create a new Dynamic project and then to copy and paste all the previous Desktop project.. you can do this in a lot of ways...
Or directly from the IDE, or simply by hand than importing again the project...
Let me know if you try one of the above suggestions :)
Moreover obviously after all of this it won't start in tomcat, you have before to configure your web.xml and so on... but at least your structure will follow the Dynamic Web Project structure standards..
Till now we are using myeclipse to for development.
Now we started development using eclipse keplar.
My first problem is jars are not deployed in webapps lib directory
which we solved by referring [link] Adding 3rd party jars to WEB-INF/lib automatically using Eclipse/Tomcat
but every time if want to add third party jar's dependency then we have to add in build path and Deployment Assembly
so please let me know if there is any workaround to add entry only in build path and this jar is automatically deployed in tomcat directory.
Thanks in advance.
Suppose here we have an example to add an external jar using eclipse kepler:
suppose we have have a project here RIGHT-CLICK on it and select its PROPERTIES...
Then click on JAVA-BUILD-PATH..
click on LIBRARIES tab and click on ADD-EXTERNAL-JARS...
now select whatever you want to add an external jar or API and click ok
after taht you will see on libraries CONGRATS you have successfully added a jar file..
go to Run > Run Configuration create a configuration node if there isn't any, go to the Classpath tab and add whatever you want: Projects, JARs, External JARs, then they would be deployed, when you run your tomcat.
Darshan,
As you have added a "myeclipse" tag, I guess you are using MyEclipse. In this case, just use the deployment assembly to add dependencies, whether it is another project or an external jar file. When added this way, it will automatically be added to the build path (you will see it in the "Web App Libraries" container in the Package Explorer, under the project).
The MyEclipse developers are looking at the possibility of synchronizing the deployment assembly when adding to the build path directly but it's not clear that this is possible. So, just use the deployment assembly, in future, for adding dependencies to web projects.
The are two "kinds" of jars in my project. One - jars made from projects which ,my project is depend from (e.g. my-second-project.jar), another - jars which are third-party libraries (e.g. hibernate.jar). The second kind of jars DOES NOT appear in deployment tmp dir while the first DOES.
I'm using eclipse 3.6, my project is dynamic web project, my tomcat version is 6.0.28. I've tried to recteate it - it doesn't help. I've also got similar web-project which works well.
I've made temporary work-around - I've put my jars directly to classpath. But this is just work-arond, but not the problem reason.
My waring/errors perspective output is clean, no connected messages whith this problem. Also I've got another "interesting" problem which might be connected whith this one. It's described here
Any help would be appreciated cause I've tried everything I can and I realy don't know what to do.
Do you have two projects, one depending on the other? And you don't get the jars from the project that the other project depends on? If so, make sure the jar files are exported from the first project: right click on the project, Build Path -> Configure Build Path... and then go to the "Order and Export" tab and tick the jar files you want to export.
I have an existing project that I'm trying to convert correctly into an Eclipse Dynamic Web Project. I've mostly got it working, however there is on issue that I'm not sure how to fix.
The project has something like 2 modules that share the same Java classes, but need to be deployed as separate webapps into the app server (Tomcat 5.5).
So the folder structure is something like
/Webcontent_root
----/app1
..../WEB-INF etc...
----/app2
..../WEB-INF etc...
Is this something that can be controlled within eclipse?
Thanks
I guess, eclipse can't control project with more than one context.
Approach I.
I think you should create three projects: regular java project with classes, one dynamic web project for first webcontent and one for second. Than tune up "Java Build Path" and "Deployment Assembly" settings.
Approach II.
Or you can create two web projects, first with classes and webcontent, second with webcontent and link to first project ("Java Build Path" and "Deployment Assembly" settings).
Create 2 web project and 1 java project for the shared java source. Both web project can use the shared project as a jar file in their web-inf/lib
As #Nantipov says, use the deployment assembly screen to make web projects get the shared java project as a jar in the library filder.
Yes, it can--just not with the UI in WTP (deployment has always been a sore spot and ongoing effort to improve). The .settings/org.eclipse.wst.common.component in your project controls what Eclipse/WTP thinks of as web content root(s) in your project. Odds are you just need to create a new folder in the project and add it as a sibling to the existing element in that file, but with a correct source-path value.
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.