How to get Two Eclipse Dynamic Web Projects Set up on WebLogic with a Different Port for Each Project? - eclipse

We currently have one dynamic web project (our main web application) already setup on WebLogic. We now need to set up a new dynamic web project specifically for web services. Our main web application was design with the context root being just / and would take years to change it to something else. So this leaves us with the alternative of making the new project listen to a different port.
I first looked into virtual hosts, but could not find out how to change the virtual host ports. Then I looked into creating a new server, but couldn't figure out how to get eclipse to see two servers on the same domain.
We have WebLogic 11gR1, PatchSet 2 and OEPE Eclipse 3.6.1 bundle.

I found out how to do it. I had to use Eclipse to create a new domain. The only downside to this is that I had to re-setup the connection pools, which is most fortunately a one-time deal.

Related

Setting up proxy filter for all application on WebSphere Application Server [duplicate]

I want to register filter class for all web application in websphere; Tipically in tomcat I specify filter in /conf/web.xml. How can I do this in Websphere 8.5.
Also what is the common library (lib folder) in websphere. The filter class is in jar file and I want to put that jar file in websphere server lib directory.
-Thanks
Unfortunately there is no easy way to do it in WebSphere. It was already discussed here - Global Filter for all Web Applications
WebSphere solution involves creating custom listener and programmaticaly attach filters. You can find sample solution and description here - Adding a servlet filter to all web applications
What is the common library (lib folder) in Websphere?
You can put your jar to WebSphere\AppServer\lib\ext directory to be shared by all profiles, servers and apps, or create a shared library via web console Environment > Shared libraries and attach it to the specific server or application.

ZK Project , Need Structural Advice for multiple ZK war applications

I need a advice for design purpose my structure of the application is as follows.
I have three module designed in ZK framework as a separate war application (web application) e.g finance-module , general-ledger and cash-account , all are separate war files can be deploy on tomcat as a separate war files,
Now I want to have a seperate war ZK application that has index or home page and have menu and from that menu I can able to call these three module or war application.
-------------------------- Main module -------------
Menu : general-ledger link , cash-account-link ,finance-module
1) This 4th Main module also has feature to user login and change user preference , means can also have code e.g view module as well as spring service.
Now the question is that how to call other war files zul pages and even if v call how to manage from 4th module and also how to share session across the four war files or applications.
Thanks
Vikas
I have worked in a similar scenario and this worked well for us:
When you create separate war's it means that they are independently running in it's own web context inside tomcat. Usually when you want to share resources like datasources, transactionManagers, or any other kind of jee resource you need to configure them at the tomcat instance level and they will be available in the JNDI directory of the tomcat server and any web application can pull any of them to use it.
https://tomcat.apache.org/tomcat-8.0-doc/config/context.html
https://tomcat.apache.org/tomcat-8.0-doc/jndi-resources-howto.html
There are several jee resources than you can share in the tomcat server but if you need more flexibility and robustness you might need a full stack java enterprise application server like wildfly http://wildfly.org/news/2014/11/20/WildFly82-Final-Released/ or any other commercial like WebSphere, Oracle Weblogic, etc
Now, if you want to share java classes, zul's or any other file, you may want to package them in separate common jars and use them in any war as a dependency and then reference them through the classpath of the web application.To organize and maintenance this modular projects Maven and Gradle are very good tools you can use.
From ZK you can call any other url of the other war's as simple as
<a href="htt://myserver/account/home.zul" label="Account"/>
<a href="htt://myserver/finnance/home.zul" label="Finance"/>
To share the session what you need is to implement a Single Sign On (there are other implementations like oracle opensso), you can configure it directly in tomcat but be aware of this Sharing security context between few web applications .
Spring Securityhas an extraordinary support for this kind of escenario.

debug GWT on tomcat using eclipse

I'm using GWT 2.4 and have a ton of code already written. I understand the Jetty server that comes with the GWT plugin has very tight control over the jars that can be used in a project to mimic app engine as closely as possible. I need to deploy to tomcat 7. I modified my project in eclipse and "blessed" it as a dynamic web project so I can export...WAR and upload it to my QA and production tomcat.
I need help with getting the app to run (and debug) on an embedded tomcat (like an honest dynamic web project would). I already have tomcat setup in eclipse and I have my CAS server web app deployed to it.
I've ready tons of either old or confusing posts here and elsewhere. Basically, I'm looking for the same debugging environment I would get with the packaged Jetty server, but on my own tomcat configured with WTP in eclipse...so I can mimic my production environment (just like Jetty mimics app engine)
any help is appreciated.
It should probably a little bit easier, but it's possible. Here's how I do it:
1. Setting up the web server
Using the JavaEE edition of Eclipse, I set up the Tomcat 7.0 server adapter, and define an environment in Preferences > Server > Runtime Environments
File > New > Project... > Web/Dynamic Web Project
Select the target runtime I set up in the first step
Important: In Context Root, enter /
I create an HTML file and a Servlet, and then try running the setup using Debug As > Debug On Server
2. Adding the GWT code server
Project > Properties > Google > Web Toolkit > Use Google Web Toolkit
Important: I always need to change the order in the Java Build Path (Project > Properties > Java Build Path > Order and Export), see http://code.google.com/p/google-web-toolkit/issues/detail?id=4479 - gwt-dev.jar must be pretty much on top of the path.
Project > Properties > Google > Web Application: War directory = "WebContent", also check "Launch and deploy from this directory"
I create some sample GWT content (I create a sample GWT project, and copy most of it over)
I try to GWT compile the project. This shows me, if I got the build path order right - otherwise, the compiler fails early with "java.lang.NoSuchFieldError: warningThreshold".
Debug As > Web Application - just to create a debug configuration. Stop the debug. Edit the debug configuration (Run > Debug Configurations...), deselect "Run built-in server". Start the debug again.
Now, finally, I can debug both the server and the client part (I still need to click two Debug icons to start both!) I can manage the client side from the "Development Mode" view, and the server side from the "Servers" view. At the end of the day, it works great, and using the "Automatically publish when resources change" feature (Servers view > myServerName > Open > Publishing), sometimes even better than with the integrated Jetty.
At first thought, I don't really see why you would be facing a problem. Perhaps, the way Eclipse is laid out is too confusing and daunting.
On my Eclipse, I had been using the default jetty as the server during GWT debug. However, there were some problems which would not be caught by jetty when deployed on Tomcat or JBoss.
And when I added Tomcat or JBoss instances to Eclipse and added my app to those server instances, the debugging worked straight away. Are you missing one piece of vital, but simple info?
Let me presume that the following would fill in your missing link ...
Locating/adding your server instance:
On Package Explorer (or Project Explorer, either one) in Eclipse, you would see, besides your personal projects, a "servers" project. Under it is are configuration nodes listing all your Tomcat instances.
If you cannot see the "servers" node in Package Explorer, it probably is due to your working set filter. (And if you don't know what working sets are ... I guess you would need to beef up on your dexterity in Eclipse).
If you don't already have a Tomcat instance, you simply right click on the "servers" project to add a new server (Package Explorer -> New -> Server ...). You would be asked the location of your Tomcat home. And your desired port number of the server instance. Of course, you would have to ensure that the port number will not clash with the port used by any other inet operation on your box.
Configuring the port number a 2nd time
On the server instance node in Package Explorer, you would find the file you should edit to set the port number to match the one you specified when creating the new Tomcat instance. If you don't know which file to edit, you would need to read up on the Tomcat version you created to find out which file contains the port number config.
You need to config the port a 2nd time because the 1st time tells Eclipse where and at what port to expect the server instance to be running. The 2nd time is to configure the server instance itself.
Adding your app to the server
However, the nodes in "servers" project only allow you to configure your Tomcat instances. There is yet another view called the "server view" to further configure your tomcat instance. You need to enable Server view from Window->Show View->Server->Servers.
Right click on the server instance in the "Server View" to add your app.
Running debug off the Maven generated target.
There are times you wish to debug the war structure to figure out which jars are missing in the war. And incrementally remove jars from your war to figure out the jars that are already supplied by the server. Since JBoss supplies many of the jars already, you would have to figure out if your development jars are of the versions as those expected by JBoss.
You would create another Eclipse project in your workspace and make an Eclipse folder softlink in your 2nd project to point to the Maven generated target of your first project. And you specify target/{maven generated webapp directory} as the webapp directory of your 2nd project. What I mean by "maven generated webapp directory" is the unzipped intermediate directory generated by Maven (used by Maven to generate the zipped war file).
This is the cleanest way to debug production war if you could faithfully replicate the production tomcat/jboss server on your Eclipse development box.
If you prefer JBoss.
Somehow, JBoss config node is not listed in the "Servers" node in Package/Project Explorers. You would need to go to your JBoss installation directory to edit them.
Remote debugging.
If you wanted to debug the app on your production box, or on a server sitting on another box, you would have to start that tomcat instance under debug. You should read up on that. You have to specify the debug port.
Then in Eclipse, at Run->Debug Configuration->Remote Java Application, you specify the app and the debug port.
The first time you debug, Eclipse "may not know" where the source files are, especially if your app has multiple project dependencies. (Why can't Eclipse search the source files from my list of projects?) Anyway, you have to specify where to find your source files. And then when your debugging traverses into another project dependency, you would have to over-write the location of the source files.
So, voila! That is how I got my debugging working. I advise you to avoid remote debugging as much as possible unless you need to diagnose production problems. Unless you are doing remote debugging, do not attempt to deploy the war to local server, but simply depend on associating the project to the server instance.
Eclipse is too confusing
I know Eclipse is too confusing and you have to wade thro its features. You just have to bear with it. Eclipse menus & views are apparently optimized for plugin-programmer-centric not user-centric.
For example, why would I go to "help" to install new software? I used to expect that "Help->Install new software" to be an instructional manual to installing new software.
It beats (and annoys me) that the Eclipse team did not combine the operations together so that I could add apps to a server instance at Package Explorer. Why not? As a user I would expect to see only a single entry point to configuring my servers.
To alleviate the confusion, I like encouraging people to download and install Springsource's version of Eclipse (STS). It's the same Eclipse, except that STS has the essential parts installed and has a dashboard pointing to compatibly installable plugins. Tomcat is preinstalled as VMware tc Server. And the views are correctly config'd to show the server instances. And the correct workable Eclipse-Maven bridging plugin is pre-installed.

Tomcat works but I can't reach http://localhost:8080/

When I run Tomcat from the windows tray, it starts and I can't reach http://localhost:8080/ Tomcat homepage, but if I run it from Eclipse, it works, my applications works, but I can't reach the http://localhost:8080/...
How to solve it? Or is it normal?
Thanks!
This maybe normal, according to this thread:
This is normal.
To see why, double-click on the Tomcat server in the Servers view. This will open the Tomcat configuration editor. Click on the "Open launch configuration" link in the Overview section. This will open the launch configuration properties dialog. Select the Arguments tab and examine the contents of the VM Arguments field.
Note that the catalina.home property points to your Tomcat installation, but catalina.base points to a ".metadata\.plugins\org.eclipse.wst.server.core\tmp" directory under your workspace.
Thus, you are running a separate instance of Tomcat. The "webapps" directory under the ".metadata\...\tmp" directory contains only an "empty" ROOT webapp plus any web projects you have added to the server. This is why you get the 404.
In the Tomcat configuration editor, you can uncheck the "Run modules directly from the workspace (do not modify the Tomcat installation)" option and catalina.base and catalina.home will both be set to your Tomcat installation.
Be aware that in this configuration, the Tomcat server in Eclipse "owns" your Tomcat installation.
Every time you start the Tomcat server from Eclipse, the Tomcat files under the Servers project in your workspace will overwrite the files in your installation.
It was assumed the most would want to keep their Tomcat installation independent from Eclipse Tomcat server, so the default is to create a separate Tomcat instance.
With separate instances, you can run the Tomcat installation at the same time as the Eclipse Tomcat server provided you modify one or both of them so that the ports they use do not conflict.
If you would like the standard Tomcat webapps present while keeping the separate Tomcat instance in Eclipse, switch to the Modules tab in the Tomcat configuration editor and use the "Add External Web Module" button to manually add the desired webapps. Note that this will add a little bit to the startup time for the server.
Note this is for tomcat versions that use WTP x1.5 (seems to be tomcat 5 or below), in tomcat with WTP(Web tools platform) x2.0 and above you no longer get that option. Instead you need to go into server properties and hit switch location which will then show a proper path. then you go into the server config (double clicking the server opens config) and change the "Server Location" to "use Tomcat instillation" (the middle one).2
Understanding Web Application Structure
A web application is a collection of web resources, such as JSP pages, HTML pages, servlets,
and configuration files, organized into a hierarchy as specified in the Servlet specification. You
have two ways in which to organize a web application: packed and unpacked. The packed form
is called a web archive (WAR) file, and the unpacked form is a collection of directories stored
on the file system.
The unpackaged format is convenient for web application developers, as it allows them to
replace individual files while the application is being developed and debugged.
However, in a deployment environment, it’s often more convenient to provide a single file
that can be automatically deployed. This reduces the deployment process to placing the file and
setting up system resources. Tomcat can also automatically expand a web application once
the server has booted. The automatic expansion of WAR files is configured in the server.xml
file as part of the element that configures hosts.
Web Application Context
Each web application corresponds to a context component, as discussed in Chapter 1, and
you assign a context path to each. The default context is called ROOT and corresponds to the
name of the server with no other context information. For example, the ROOT web application
on your local machine will correspond to http://localhost:8080. If you’ve configured Domain
Name System (DNS) settings for your server, it may also be accessible from a location such as
Users access other web applications by requesting a context relative to the server. For
example, users can access Tomcat’s manager web application with the following URL:
http://
localhost:8080/manager.
Applications that you place in the webapps folder are named after the directory they’re in.
So, you can access the web application in the tomcat-docs directory with the following:
http://localhost:8080/tomcat-docs. Each application on the server is known by its name,
and users can access resources according to the remainder of the uniform resource locator
(URL) after the web application’s name.

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.