Rougher
Rougher

Reputation: 852

Using configuration in JAVA - best practice

In my case I have:

  1. LangDetector is java project with HtmlTags.config that exported to LangDetector.jar.
  2. LangDetectionService is java jersey service that exported to WAR file. LangDetectionService uses LangDetector.jar (has reference in buildpath)

When I deploy WAR file on tomcat, I don't see HtmlTags.config in $CATALINA_BASE/webapps/LangDetectionService.

I tried to add HtmlTags.config to LangDetectionService also, and after deploying HtmlTags.config is in $CATALINA_BASE/webapps/LangDetectionService folder, but it doesn't work.

What's wrong here? What's the best practices to do it?

Upvotes: 0

Views: 122

Answers (2)

Rougher
Rougher

Reputation: 852

It's solution. 1. Add HtmlTags.config to service project. 2. Change line "Configuration.class.getResourceAsStream("/" + configName)" to line "Configuration.class.getClassLoader ().getResourceAsStream(configName)" . 3. When LangDetector.jar will load HtmlTags.config it will get it from service project (behavior like in .NET)

Upvotes: 0

ilvez
ilvez

Reputation: 1285

  1. Check that HtmlTags.config is inside LangDetector.jar. It should be directly under jar file root.
  2. Check that LangDetector.jar is inside LandDetectionService war file WEB-INF/lib

If it is like that, HtmlTags.config should be in classpath and readable to your service. But what code should read this HtmlTags.config file is unclear from your question.

You can try to read this file like that:

log.debug("HtmlTags.config exists: " + new File("HtmlTags.config").exists());

, where log is your logger.

And like always, you should start checking your server and application logs for errors and warnings.

And your question leaves me wonder, why you need to see that file in that directory? If you want to read it from your application, then it should be in classpath. Physical location is not really important, or is it?

Upvotes: 1

Related Questions