• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 712
  • Last Modified:

i want to use same ehcache.xml for different projects

i want to use same ehcache.xml for different projects


Where i put the ehcache.xml common for two projects

please help me
0
Manikandan Thiagarajan
Asked:
Manikandan Thiagarajan
  • 2
  • 2
2 Solutions
 
mrcoffee365Commented:
There's no magic answer.  You'll have to pick a place you think is reasonable for both projects.  If they are usually installed together, you could have one of them read from the location of the other project.  For example, put your xml file in the WEB-INF directory of ProjectA and have ProjectB read from ProjectA's xml file location.

Or pick a separate location.  There are problems with all of these.  Some people create a program invoked at install time to check if the required xml file exists in a reasonable location, and configures the new project to use the existing file.  That's more work, and usually means you can't rely solely on a war installation (if you are doing that).

So as you might expect, the solution is really up to you.  No magic.
0
 
Manikandan ThiagarajanSenior consultantAuthor Commented:
package com.sm;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
/**
* A simple example Java client which uses the built-in java.net.URLConnection.
*
* @author BryantR
* @author Greg Luck
*/
public class ehCacheClientParentCall{
private static String TABLE_COLUMN_BASE =
       "http://localhost:8080/Parent/ehcache.xml";
private static String TABLE_COLUMN_ELEMENT =
       "http://localhost:8080/Parent/ehcache.xml";
private static Ehcache widgetCache;
/**
* Creates a new instance of EHCacheREST
*/
public ehCacheClientParentCall() {
}
public static void main(String[] args) {
       CacheManager manager = new CacheManager(TABLE_COLUMN_BASE);
        widgetCache = manager.getEhcache( "widgets" );
        System.out.println(widgetCache.getSize());
}
}
i have error when i pick other project
0
 
Manikandan ThiagarajanSenior consultantAuthor Commented:
the error is

Exception in thread "main" net.sf.ehcache.CacheException: Error configuring from http:\localhost:8080\Parent\ehcache.xml. Initial cause was http:\localhost:8080\Parent\ehcache.xml (The filename, directory name, or volume label syntax is incorrect)
      at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:77)
      at net.sf.ehcache.CacheManager.parseConfiguration(CacheManager.java:273)
      at net.sf.ehcache.CacheManager.init(CacheManager.java:231)
      at net.sf.ehcache.CacheManager.<init>(CacheManager.java:169)
      at com.sm.ehCacheClientParentCall.main(ehCacheClientParentCall.java:28)
Caused by: java.io.FileNotFoundException: http:\localhost:8080\Parent\ehcache.xml (The filename, directory name, or volume label syntax is incorrect)
      at java.io.FileInputStream.open(Native Method)
      at java.io.FileInputStream.<init>(FileInputStream.java:120)
      at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:74)
      ... 4 more
0
 
mrcoffee365Commented:
Do you mean that code works within one project?

In that case, it's probably the "localhost" part.  You have to have ea way to identify the 2 different projects in your web server.  Can you use a url in a browser to get the xml file?  If not, then you don't have a correct configuration.

In my experience, it usually works better not to use "localhost" but to have a real domain name.  If you are developing on a machine without a public host name for your server, then you put the alias in your hosts file.

Work on being able to get the xml file from a browser and that will give you a url which works for projecta and projectb.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now