I have two Spring-based web projects open in Spring ToolSuite that I need to be able to work on and debug in at the same time. However, I am running into difficulties.
Project A is a standard MVC website project, Project B is a webservices host that performs a lot of backend functions for Project A (and others).
Project B distributes a number of Model and Service classes that Project A consumes through Maven as artifact jars.
Project A runs on one instance of tomcat (actually STS TC Server) on port 8080.
Project B runs on a second instance of tomcat (standalone tc6) on port 8083.
If I have Project B closed in STS, both projects run fine and everything works. However, if I have Project B open and try and start the tomcat instance that Project A runs on, I receive all sorts of exceptions concerning missing classes that would be found in the Maven artifact.
I need to be able to run and debug both projects at the same time ideally as we develop new services and clients but this is proving impossible due to the above problems.
We have tried making the Project B a required project of A, changing build-path properties to try and force those classes onto the buildpath for A and so on, but nothing has worked so far.
Does anyone have any experience of this sort of problem and a potential solution? One of the guys on the team has used two instances of Eclipse to work around the problem, but running two instances of Eclipse is slow and clunky and has it's own issues tbh so I would rather avoid this if possible and stick to one IDE instance for debugging.
Any suggestions gratefully received.
if it is a maven project you can start it up outside eclipse by
mvn tomcat:run
then you can connect to it with the debugger as a remote app if needed
Related
I do have own developed Java library (MyLib), which I later publish on private Maven repository and have it as Maven dependency in another webapp project (MyWebapp). If I have both projects - MyLib and MyWebapp at the same time opened in Eclipse - is there a way somehow to configure MyWebapp so, that local changes made to MyLib would be directly added to MyWebapp while building/deploying it? The issue is that during development it is not really comfortable always to make some changes in MyLib, make a build, deploy to Maven repository and then make a MyWebapp build, deploy it and only then I can see how the changes are affecting the webapp project...
I would like to reduce the overhead while developing and willing to see how changes are working out. Of course when it comes to real releases the above described flow does really make sense and works great.
Thanks!
There is no simple "just tick this option" solution, unfortunately. You can chose between these options:
Convert MyLib into a Maven module and add it to the sources of MyWebapp. This, of course, will make it harder later to reuse the library alone.
Stop deploying the application. If you look at the classpath in Eclipse, m2e should have added the dependency as a project from the workspace (instead of depending on the JAR in the repository). If not: There is an option for this.
The next step is to create another project which depends on Jetty and MyWebapp. Create a Java application in there (i.e. a file with main()) which creates a Jetty server and configure it to use the current classpath. That way, you can start the webapp just like any other Java application without deploying - Jetty will simply load classes from the classpath that m2e assembled.
I have almost no experience in using netbeans and svn so please correct me gently if I am wrong. I come from using python/vim/git so workflow wise is foreign to me.
Currently, I used the Netbeans' svn plugin to checkout my project from a remote repository. The project has several components like webservices, and also a swing client and of the business logics.
Assuming that I need to work with the web services and the swing client, do I create separate projects for each, and import the project as references?
Finally, currently I'm using netbeans to test the webapp on the local glassfish server. How do I deploy on a remote test server so that my team mates can use and test the web app?
If all of the seperate components are a part of the same project in svn then, no, you should only create one project in netbeans. Check out the project from svn and once netbeans has checked out the project it should prompt you to create a netbeans project when it does select project from existing sources, follow the wizard steps and your project will be created. You will have to import any external jars needed by the project that has been checked out into the newly created project in netbeans. NOTE: Netbenas will create a build.xml file for the newly created project so be sure that you do not commit that build.xml file into the repository unless it's needed.
To setup a remote server in netbeans go to tools->servers, select add server, select the server type(glassfish, tomcat, etc) then enter the pertinent information for the server using the wizard.
First question "Assuming that I need to work with the web services and the swing client, do I create separate projects for each, and import the project as references?"
It really depends on your architecture - how coupled are those components. It's also important what packaging system do you use? For example if you use Maven you can easily modulate the project and define dependencies between the modules. Check out this for details. I am referring to maven as it's build-in in Netbeans.
Regarding your testing you basically have 2 options:
a) expose your glassfish to your buddies
b) package and deploy your project remotely - this really cannot be given straight answer - depends on your infrastructure, where's the remote server, how big the deployment package is, how the application server behaves regarding hot deployments etc.
I suggest try the first option.
SVN helps you to keep the project in several versions in the repository.
You can always checkout from repository.
once you checked out, you will be using the project from a saved directory somewhere in your local machine.
Now, you can keep on developing the project, at the same time your friends can also keep doing that, and whenever you think you have done enough changes or development then after verifying your own copy of the project, you can commit the changes to repository.
After committing the changes will be visible in the repository to everyone, and hence anyone can access this updated version of the project residing in the repository.
Note that the earlier version will not be deleted, unless you do so.
Your friend can also checkout a copy of the project from the repository and they can merge it with their existing ones, and they can also commit the changes.
and at the same time, you can ask your friend to check your developed code by checking out the project and deploying on their local server.
I hope it gives you a better picture.
See title. I would also like the project to redeploy after every change. I am new to this area so my knowledge isnt that good. I tried googling and searching here, but I can't find any answer.
thanks for any help
There are two plugins that combined together in Eclipse work quite well together to perform what you want:
M2E: M2Eclipse which handles everything related to Maven.
Eclipse Web Tool Platform (WTP): which handles everything Java EE related (Tomcat, JBoss, etc...)
For M2E to work properly with WTP, you need to add m2e-wtp. You may find several useful information as well as some good links here.
I would start from the Eclipse Java EE distribution (it includes already Eclipse-WTP) and then add M2E (either with their update site or through eclipse market place: look for M2E and M2E-WTP).
From there, you create a Web Project and you can run it on a Tomcat server. The first time you try to run you project on a server, you will install Tomcat and it will appear in view named "Server". Double click on the server to configure ports, automatic deployment etc...
You can easily deploy a webapp using the Cargo Tomcat plugin. Here's helpful articles on this topic:
Maven Tomcat Deployment using Cargo plugin.
Autodeployment with Maven, Tomcat, and Cargo.
I am considering using Maven 3 for my Spring projects which I have been developing using Eclipse and Tomcat. Until now;
I have been disabling "Republish automatically" because sometimes I don't need publish, I only save .java files (classes) and keep development on debug mode.
I republish (by clicking Eclipse's "publish" button on Servers view) only when I changed js, jsp or htm-like files, not class files, so I can keep developing without restarting Tomcat.
Now I am going to use Maven for debug/run on development but whenever I changed my code, I don't know how to do this "publish" issues on Maven as it doesn't use Eclipse's Tomcat directly. I stop maven and start again. Do I have to do this for all changes on my code? How can I make this maven -tomcat:run- "publish/republish" for js/jsp/html files and "do nothing" for .java files?
Unfortunately, yes, you'll have to run maven for every change.
Maven't isn't really intended to be used this way - it assumes that you're going to use maven when you're ready to build (ie after development), but use something like Eclipse if you're trying to see your changes in real time. It has no mechanism for listening for changes.
For my webapps I use both maven and Eclipse, with the m2e and the 'Maven Integration for Eclipse WTP' plugins. With that setup I can see my changes in real time using an embedded Tomcat instance in Eclipse, and when I'm done, I use maven to build.
Give those two plugins a shot - I think it'll meet your needs.
I had the same problem. And it happens because I ran maven eclipse:eclipse. Then, Server stop publishing (click on publish and said it was synchronized). I downloaded again .classpath and .project and other innerit files of eclipse project structure from cvs and server starts publishing again. May be this could help.
Regards,
For the benefit of Googlers:
I was getting NoClassDefFound errors using tomcat:run to start the app.
It took some googling but the following post notes that using tomcat:run-war enables your dependencies to get picked up from the WAR:
http://www.hascode.com/2010/06/java-server-facesjsf-2-tutorial-step-1-project-setup-maven-and-the-first-facelet/
However, for debugging and hot code replace, it's simplest to run Tomcat from the Servers view in Eclipse.
I created an IntelliJ (9) project, and it started off as a single maven pom.xml project.
This project is a spring mvc web application.
I now realize it will be better to actually have 2 spring mvc applications.
Since I use maven now to build and run the application (using the jetty plugin), should I create the 2nd spring mvc application in the same project?
If so, I guess I have to re-work the folders so it is like:
myapp-models/
myapp-spring1/
myapp-spring2/
So this way each spring app will have:
/src/java/main/webapp (or whatever it is, I used a simple web arch type)
Does this make sense?
Do I even bother setting things up in IntelliJ to build using the IDE? (using modules I think?)
Can I still build and run using intelliJ?
BTW, when browsing folders in IntelliJ, it is annoying to keep clicking through the first 3 folders since they are empty, is there a faster way?
This setup is just fine. You may choose which artifacts you want to deploy on Jetty. myapp-spring1 or myapp-spring2 or both. (Maybe artifacts were introduced after IntelliJ IDEA 9.)
BTW: I usually use "View as Package" in the Project tab. There you can select "Compact empty middle packages". At least in IntelliJ 10/11, but Im sure there is something similar in version 9.
You are correct in using multiple modules in Intellij. I create multi module projects all the time.