When not to use this server location when using tomcat within Eclipse - eclipse

When using tomcat within Eclipse why would I ever not want to use the tomcat installation as checked in the attached image. I always use the "Tomcat Installation" Are there advantages/disadvantages of using the other Tomcat server locations.

In fact, I always Use Workspace Metadata. When you say Use workspace metadata, Eclipse copies your files (class files, jsps, server.xml, context.xml) to /.metadata/.plugins/org.eclipse.wst.server.core/tmp0. It then starts Tomcat using these files. It does not change the Tomcat installation directory at all. Note that this doesn't copy the tomcat files, just the files which come from your project.
If you choose Use Tomcat Installation, then it copies your files into the Tomcat installation directory, and boots it from there.
If, like me, you're developing multiple projects from multiple workspaces, then this makes a big difference. With Use Workspace Metadata you will never get any interference between workspaces. For instance, it's possible that when rebooting Tomcat, one project will be in a bad state and your logs will be filled with stuff from another project. It's better to have two separate locations, and the workspace is a good place for this.

Always try to use use workspace metadata ...
this option delpoys the web app in the workspace directory
~WORKSPACE\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
so you have different work spaces for different projects , you will have applications deployed in different spaces and this solves ambiguity in deployment.
even if you have singe application, this is recommended
if you select
use tomcat installation... ,
you will have to be careful while dealing with multiple applications as the old application will be overridden by the newly deployed web application.
when you select
use custom location ...
then you need to be more careful while handling multiple applications as you manually give the locations for deployment

Related

Tomcat and Eclipse vs Intellij

I am working with Intellij but some of my co-workers don't. When I was writing install doc, I realized that Tomcat is not managed the same way on the two IDEs.
Which is a problem considering what happened next when I tried to set up our project on Eclipse.
Basically, on Intellij, you select a Tomcat on your computer and it will literally copy the war into the webapps folder and run the server with everything working fine.
I am not a user of Eclipse so I might have misunderstood something, but I found that when you create a Tomcat server, it will embed the one you gave it to it. Doing that is a bit of an issue when you are working with logback, because usually you set your logs location directly into the Tomcat folder. And in Eclipse you are working out of this folder.
So, I can't run my application because it can't find the location of the logs folder at the fine place.
Is there a way to use Tomcat in Eclipse like Intellij? Or did I just miss something because I am kind of new with Eclipse?
See the FAQ: (1) (2)
I found that when you create a Tomcat server, it will embed the one you gave it to it.
You have to be more specific with your description. How you do things and what do you see. What do you mean by "embed"? What is the actual failure that you are observing with your logging?
There are different ways to do things.
For me by default Eclipse does not embed Tomcat, but runs it as a proper java process. (org.apache.catalina.startup.Bootstrap) You should be able to see it with jconsole and similar tools.
It runs your web application expanded, i.e. without zipping it into a war file. It creates a separate configuration of Tomcat, i.e. runs it with separate CATALINA_HOME and CATALINA_BASE directories (as documented in RUNNING.txt file of Apache Tomcat). The CATALINA_HOME directory stays untouched and CATALINA_BASE directory is ${workspace}/.metadata/.plugins/org.eclipse.wst.server.core/tmp0 etc. A logs directory can be found there.
One known caveat is that java.util.logging is not configured by default (the system properties java.util.logging.manager and others are not set). See "How do I enable the JULI logging" item in the FAQ. -- In the same way you will set any other system properties that you may need.
The default configuration of java.util.logging (as provided by JRE) is to log everything to the console, without creating any files.

How to call an ant target / maven after JBoss Tools Deploy?

Is there any possibility to run ant after, let's say a clean of a jboss tools server?
e.g. i plan to move some directories after having deployed them to a different directory to speed up things in jboss start up.
Another solution which came to my mind was to make jboss tools call a specific "start jboss" task/bat/something which would result in first calling my own 'move files' target then starting jboss
[EDIT - solved]
So the working solution for me was a comination of ant and jboss tools.
I use jboss 6.0.0 and jboss tools 3.2 i think
So double click the jboss 6.0.0 server, click on the tab deployment (it's a usability fail imho that this important tab is at the bottom of the view/window).
Now click on your dynamic web app module name in the list. Redirect the deployment location to yourwebappname.ear/yourwebappname.war
Use the jboss deploy folder
Move all lib files from the war/web-inf/lib to yourweappname.ear/lib
I could move all of them except spring-web-2.5.6.jar
Delete them in web-inf
eventually create and fill the meta-inf directory in yourwebappname.ear/META-INF (i did it at least) with application.xml and manifest.mf
thanks # sir Andersen
You do not reveal what kind of moves you exactly want to do and no, there is no direct support to call out to Ant or similar after a clean in JBoss Tools deploy.
But depending on what you actually want to do one or more of the below options might work for you:
Use custom deploy directory for the server
If you just need all deployments go to a specific directory then just set a custom deploy directory for the server - no need to move anything.
This is done by double clicking on the server and in the server editor under the deployments tab you can control the root directory.
Use custom deploy directory and name for specific deployments
If you need more finegrained control then you can also use the Deployments page described above to set the relative directory and name for deployment for each individual module.
Have a Ant task setup as eclipse external tool builder
If none of the above works then you could setup an Ant task as external tool builder under Project Properties. This ant launcher you can even limit to only run when certain resources changes inside the eclipse workspace - you might be able to use that to control when you want to do the "move some directories".

Removing environment specific properties from wars, ears, and jars

At my company, we use Weblogic (depending upon the installation anywhere between versions 6.1 to 11g).
Right now, we embed environment specific variables into our ears, jars, and wars. This even includes the weblogic.xml file where we have something like this:
<working-dir>/opt/bea/wl61/server/domains/deploy/prod3/temp/work</working-dir>
That means we have to rebuild the same jars, ears, and wars for each and every environment. And, if there's a change in the environment, we have to rebuild and redeploy the wars, ears, and jars. You can imagine the issues and problems we have with build and release management (which is my job).
At my last position, we used JBoss, and somehow were able to create generic and deployable ears. I would have Hudson build an ear that the developers could use for their testing. This same ear could then be passed to our QA team in their environment, to UAT, staging, and into production.
We could do this amazing feat because we configured JBoss to look for properties files OUTSIDE or the ear itself. There was a config directory that was a sibling to the deploy directory that contained any needed properties files. Is it possible to setup Weblogic to do the same thing?
We need a way to do this with minimal code changes. I've already examined the source, and we don't specify the directory name when we specify loading the values in the properties files. Therefore, we might be able to do this with some sort of CLASSPATH idea.
I understand that these properties must live somewhere, but I would prefer if it could be configured in the environment, and maybe done by having the path relative to the deploy directory. I want to use the same ear, jar, and war files no matter what system you are on: Windows PC desktop, Linux, Mac, or Solaris server.
The toughest issue will be our weblogic.xml embedded path. Can that path be relative to the deploy directory and not from the root of the system?
As I stated before, I'm the build manager, so as far as everyone is concerned, this is my headache, and not their problem. If deployments don't go well, the Finger 'o Blame can point directly at me.
In order to get this to done I have to be able to find a solution that's simple for us to implement. We can't rewrite everything and change everything around. Otherwise, I can't get the other teams to do this. After all, it's my issue and not theirs. We need something with minimal coding changes (preferably none) and minimal changes in our Weblogic setup. I want something that in Version 3.4 of our software, we do it the old fashion environment specific way, but in Version 3.5, we can deploy in an environmentally neutral way and do that with minimal changes in our deployment environment.
I can feel your pain - I went through the same process at a couple of companies. You have a couple of options that would be a significant improvement from your current setup:
1) Modify the CLASSPATH to use an external directory / properties file that overrides everything that is in the ear file. This is easy to implement but can get out of hand without the proper standards/governance.
2) Use deployment plans to define environment specific variables. However, deployment plans were not introduced until the WebLogic 9.2.
3) Roll all of your environment specific files in to its own jar. All environments would be pointing to the same file but it would be building out different contents based on your build process. Advantages - Single file that contains all the props, easy to move, etc. Disadvantages - Cannot change properties on the fly and force a reload from the JVM.
There may be other options based on the repository. IMHO, all of these work more or less the same - It's the process and enforcing it that prevents issues.

Controlling catalina_home in liferay eclipse tomcat

I have a development system ( linux-Liferay6-tomcat6-Eclipse Helios) that I have version-controlled in SVN. When I roll it out for a new developer in what amounts to a fresh installation, the paths for the tomcat server are wrong because they were written in various places as absolute paths reflecting my desktop.
It looks to me that I could modify catalina.sh or startup.sh to fix this problem, or part of it maybe, but I'd rather have a fix that leaves Tomcat unmolested. I could also require developers to set CATALINA_HOME, but that would break any other tomcat installations they might have ( my own situation in fact).
For instance, maybe a custom Ant script that figures out the path and sets CATALINA_HOME just for the shell thats running this particular Tomcat? Is there a way to do this in the Eclipse IDE, I looked but don't quite see it?
Ideas?
John Fisher
If you're using ant and the liferay plugins sdk, you're supposed to create a build.${username}.properties file in the root folder of the plugins sdk. (substitute ${username} with the name you log in to your OS). In this you override the location of your appserver, e.g. tomcat. Take a look at build.properties. Though you're not supposed to change this file, you can copy the one interesting line (note: it's preconfigured for tomcat) and use it for the appropriate settings.
This way you'll have a per-user setting for the required value.
The server (if you require to start it in eclipse) is to be created in each eclipse instance, independent of each other. The Liferay IDE plugins for eclipse can help you with setting this up.
As I expect the server to be modified by everybody on a frequent basis, I never share the server "project" in version control, but keep it strictly local. It's easily recreated if lost.

Configure project in eclipse so that it ends up in the tomcat "common" class loader

I have two tomcat web applications that need to share information using a singleton. I have already made it work by placing the jared classes in the tomcat common directory. Each webapp then gets the same copy of the singleton. What I would like to do is to integrate this behavior within eclipse. I would like the common classes to be a single project that gets incorporated into the tomcat common class loader every time I start the tomcat server within eclipse. Anyone knows how to configure eclipse to do this?
May be one possibility could be to extend the tomcat class loader in order for that class loader to search in other directories than WEB-INF/lib, this by:
Extending org.apache.catalina.loader.WebappClassLoader and override the findClassInternal method.
Configuring Tomcat to use the extended classloader.
This is done in the appropriate webapp configuration file under the Tomcat conf/Catalina/hostname path with the following element:
...
Then in eclipse, you could set your common project on the "Required projects on the build path", which makes it part of the classpath.
That means your extended classloader must be able to look for other classe:
either in a fixed pre-defined path
or in a pre-defined path within the classpath.
Not tested myself, but may be that can give you a lead on this issue.
A much simpler solution is proposed by noselasd in the comments, taking advantage of the GlobalNamingResources Component of Tomcat.
However, the FAQ does mentions:
When you create a new Tomcat server in Eclipse, the New Server wizard assumes it is not safe to affect the current behavior of the Tomcat installation that this new server will use.
WTP is able to avoid affecting the behavior of the installed Tomcat by using Tomcat's ability to run multiple server instances from a single installation. Thus, the default configuration for each new Tomcat sever you create will be a new server instance of the Tomcat installation associated with the Tomcat runtime selected in the wizard.
If you expect the new Tomcat server in Eclipse to run the same instance that the default batch files in your Tomcat installation run, you will likely be surprised when the Tomcat server in Eclipse doesn't behave as expected.
The Tomcat server configuration can be changed so that it does run the same instance as your Tomcat installation.
You will find here how to modify the server.xml in WTP.
I've managed to get it working. Here is what I did:
Created a common project in the eclipse workspace.
Created the two web applications, called first and second, that should share the common project.
When the web applications are created a Servers project is created with the tomcat configuration.
Change catalina.properties inside the Servers project and add the line shared.loader=/path-to-workspace/common/bin.
This works perfectly for development. Every time a new build is created everything is in sync. For deployment You need to convert the common project into a common.jar and place it in ${catalina.home}/lib.