Integrating JRebel with custom Ant/Ivy/Tomcat web application with Spring MVC - spring

I am trying to get JRebel working with a fairly large enterprise web application which uses Ant + Ivy for building/dependency management, Spring 2.0 framework and Spring MVC, and all this has to be built and deployed to Tomcat.
I have JRebel enabled on Tomcat and the Project itself. Remoting is not enabled as I assume that if Tomcat and the project are on the same machine, this is not needed. When I start the Tomcat server from within STS, JRebel appears to load fine and I see no (apparent) significant errors.
However, any changes to the project do nothing with regard to deployment, and I see no JRebel messages in the console. The project itself is a somewhat nonstandard layout and does not have the traditional WEB-INF/src structure. When I enabled JRebel on it within STS, it just dumped a rebel.xml file in the root directory.
For reference, the project is based on this codebase and has the same general structure: https://github.com/NCIP/c3pr/tree/master/codebase
While the JRebel guides are good, they only show JRebel being used with very simple projects and do not go into very much depth into exactly how the service works.
Any suggestions, resources, or ideas are greatly appreciated.
thanks

Did you actually recompile (doesn't matter if you use Eclipse or javac) those classes that you changed? It might be a good idea to check if you have "Build automatically" enabled under the "Project" menu.
They way how JRebel works is that it actually monitors the compiler output folder (usually "bin" folder or "build/classes" or something similar).
This folder (or folders) is specified in the rebel.xml file and the file must be in the classpath of your application while you run it (WEB-INF/classes or on the jar file root or in the exploded dir).
Can you make sure, that rebel.xml is actually in the applications classpath?
Also, you should see the message in the console that says something like:
"JRebel: Directory '/path/to/project/bin' will be monitored for changes.".
And also, if you see the JRebel banner in your console, it is useful to check if the license is found (if it is not found then JRebel will not work).
Sometimes there may also be some mismatch when your Eclipse compiles classes to the "bin" folder and your build scripts compile them to under "build/classes" and only one of these locations is specified in the rebel.xml file. In this case, JRebel will monitor only one of them and then it is confusing too.
Wishing the best,
Sigmar

Related

Liferay portal deployment going into loop

We are using STS 3.4 to develop Spring portlets for Liferay 6.1.2. When we deploy the project onto the server by droping that on the server view, the deployment never gets completed.
It says the deployment is complete and portlets are ready to use but it again reinitiates the deployment process.
Any idea why this endless deployment loop is happening?
I'm not sure if STS is aware of Liferay's additional deployment process (or if you need/use it): Liferay typically processes a WAR file before actual deployment to tomcat, thus you should drop your WAR file to Liferay's deploy folder. This might add some libraries from Liferay itself (depending on your configuration in liferay-*.xml files or some other necessities that I don't remember.
Especially if you use Liferay's Plugins SDK (you don't state if you do or if you don't). If you indeed use it, you might want to try the Ant target direct-deploy for building the WAR file: The result of this should be able to deploy directly to tomcat. I'm assuming that STS omits the Liferay deployment process (and direct-deploy would mimic it). I hope (from memory) that it was available on 6.1 already.
Can't go without the hint that you should upgrade.

Maven in Eclipse?

I am a total beginner at maven, I have read about it online but I am still confused how it can be used. I have eclipse Oxygen version installed and when I open projects I can see maven project option is already there. I was even able to create a maven project using YouTube tutorial. But now then I saw popular plugin called m2eclipse but I am not able to comprehend why is it actually used; when my application ran without it.
I am learning maven to get started with spring boot but I am finding it really overwhelming where to begin with, and many of the tutorial sites state to download maven (But maven already comes along with eclipse?)
Please explain.
Apache Maven is a build tool - a tool for compiling the source code of a project into a program that you can run (for example a jar file, or a war file that can be deployed on a Java EE application server). Besides automating all the tasks for building a project, it also gives you a standard way to organize your project and to keep track of dependencies (libraries that your project needs).
Why do you need such a tool?
When you write a small program that consists of one, or maybe a few source files, it's easy enough to compile it by hand on the command line, by directly using the Java compiler javac that comes with the JDK.
But when your project becomes more complex, and you have hundreds or even thousands of source files in multiple modules, it becomes really hard to keep track of everything and cumbersome to compile the files using javac. If your program needs libraries, it becomes even more complex, because you have to make sure that all the libraries are on the classpath, and some libraries need other libraries, which also have to be on the classpath.
A tool such as Maven helps you to compile all the source files in the right order and to keep track of all the libraries. Maven can automatically download libraries from the web and add them to your project, and downloading everything and building the whole project can be done with one simple command such as mvn clean package.
Spring Boot is part of the Spring Framework, which is a huge framework with tons of useful functionality for developing projects in Java. A Spring Boot project typically needs dozens of libraries, and it would be very hard to use if you'd have to keep track of all those libraries by hand - so that's why it uses Maven to manage all of this for you.
A Maven project is configured using a file named pom.xml - in that file, you describe your project and you put a list of libraries that your project needs. When you build your project, Maven will read the pom.xml file and figure out automatically what source files need to be compiled, and what libraries need to be downloaded.
m2eclipse comes preinstalled in Eclipse (at least when selecting "Eclipse for Java developers" or "Eclipse for Java EE developer"), thats why you were able to use Maven by default.
Still you probably want a command line Maven, because that's most likely how it will eventually run on the CI server, sometimes Eclipse Maven installation can produce different result than the command line install.

How do you prevent Liberty from expanding a published WAR file

We are using some library that doesn't work for some reason if the WAR is expanded under the apps folder. When the eclipse tooling publishes the WAR to a remote server, the WAR is expanded. How do I prevent the server from unzipping the published WAR?
If an app doesn't work when expanded, but the exact same app works as a binary, then that indicates something wrong in the server. I'm not aware of specific cases where we wouldn't support an expanded EAR instead of an EAR binary.
It sounds like you're this far already, but the first thing to check is if you're using resources inside of the workspace or inside of the server. You can check this by looking at the server on disk and seeing if the apps directory has either something like TestWar.war.xml or TestWar.war (directory).
To move the resources to the server, if you are using something like WDT (the Eclipse tooling you get from dragging the icon on wasdev.net into your Eclipse workspace) you can modify the Liberty server settings to do this.
In the Servers tab, double-click the WebSphere Application Server Liberty entry and you should see the Overview configuration screen. Uncheck Run applications directly from the workspace and now if you look at the server on disk you will see the files directly inside of the server.
But, to answer your question, it's not so much that we're unzipping the published WAR so much as we're not zipping it to begin with. If you right-click the EAR project and go to Export that's a one-off way to make an EAR binary, but otherwise you may want to look at a simple build description system through Ant or Gradle or Maven along with similar standards to build the archives.

Find java ee files on a VM

I'm working on a Java EE project made by someone else. They put this project in a VM and I can access to it to run the app. But the problem is that I can't find all the files of the project. Indeed, the project is using the model-view-controller and I find only the .jsp files (view). The app uses JBoss, Tomcat, Maven and Catalina. I have to start JBoss and Tomcat and then, in localhost, the app is running. So it works. I'm asking myself if there is a place defined by one of those technologies where I can find the other files. Because, they should be on the VM because the project is running well.
Can someone know if there is a global repertory for those files ?
Your VM will most likely contain only a runtime environment for the web application, consisting of a JBoss installation (including Tomcat) and the deployed application (in webapps folder), typically as a decompressed (exploded) WAR. See Deployment for an in-depth description of the web application's structure.
If you plan on modifying the application, the runtime environment will not help you much, because it typically does not contain the Java sources, but only their class files. You will instead need a development environment, consisting of your favourite IDE and the web application project, checked out from some revision control system (CVS, SVN, Git etc.) at best. This is the place where you can write/change code and JSPs and eventually build a WAR (e.g. using Maven) for deployment in the runtime environment.
Seems to me you should rather look for your files in a development environment.

Update dependencies while in hosted mode in GWT

I have a GWT webapp split into two Maven projects where one is a dependency to the other. Each time I change something in the dependency and I'm running webapp in hosted mode I have to rebuild the subproject and restart hosted mode for changes to apply. It takes a lot of time so I'd like to ask you if there is any way to make GWT using "live" version of the dependency?
There are 2 cases:
for server-side code, assuming you use the DevMode's embedded server, rebuilding the app and then refreshing the server should be enough
for client-side code, AFAICT, you have to use the source and output directories of the dependency module rather than the JAR containing them (GWT will load the source from the classpath, but apparently it'll only see the modified sources if it comes from a folder rather than a JAR; at least that's what I found in my tests). This goes against The Maven Way™ but the only solution so far is to use a special profile that will import the sources of the dependency project as sources of the project you're running. You can see examples of that in my archetypes.
There's actually a bug opened for the gwt-maven-plugin, MGWT-332, to do that automatically when running a reactor build. I also mused about what's really needed, for the forthcoming official gwt-maven-plugin (rewritten from scratch, independent from the CodeHaus Mojo plugin).
If your dependency does not come from a reactor build, then you're out on your own: you chose to make it totally distinct, so that's how it'll behave: you'll have to release it (even a snapshot) each time you make a change to it, and use the new version in your app (which means re-launching the DevMode).
This can be circumvented by running DevMode on your own, without the help of the gwt-maven-plugin. You're left on your own managing the classpath though (using the Google Plugin for Eclipse, I suppose you could simply edit the launch configuration to add the source folders of your dependency project to the classpath, before the classpath provided by Maven, that would reference the JAR).
Remove the dependent other application jar file from the primary application lib folder under webapp.
Eclipse should then resolve the dependency using the other project in the workspace if you have added it to your primary application classpath.
As GWT build takes ages, we invested some money in a JRebel license. We have two separate Eclipse projects for our back-end and our GWT front-end. JRebel reloads the classes automatically and I never need to restart my local server while writing code. It proved to be a wonderful time saver. Definitely worth the investment.

Resources