?
Solved

Struts and Servlet Together

Posted on 2006-04-29
14
Medium Priority
?
536 Views
Last Modified: 2013-11-24
Hi Guys,

One question.

I have one Struts web application in Tomcat 5.5 using JDK 1.5. Another technology used is Drools Rules Engine.
Thus, I was thinking to load the Drools rules engine (which took around 5-6 seconds) while I run the Tomcat. So this means that I need to create a Servlet with the init() method in it. Well, so far so good.

Now, the questions starts to come out. If I store the rules engine in [MyWebName]/WEB-INF/classes/rules.xml, how can I try to load it? I thought that in init(), there is no way to open file, am I right? I do not want to hard code the path unless I have to. Any solution or better idea?

David
0
Comment
Question by:suprapto45
  • 8
  • 6
14 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16569160
Just allow the classloader to do it with getResource(AsStream)
0
 
LVL 16

Author Comment

by:suprapto45
ID: 16569172
Hi CEHJ,

Thx. Yeah I found that method as well but I have no luck trying it. Do you have any URL to show how to use it?

David
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16569182
Show me how you'd load the rules file normally
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 86

Expert Comment

by:CEHJ
ID: 16569184
(showing the classes involved)
0
 
LVL 16

Author Comment

by:suprapto45
ID: 16569194
RuleBase excelRules;

InputStream is = new BufferedInputStream(new FileInputStream(properties.getProperty("excel.decisiontable.path")));
excelRules = DecisionTableLoader.loadFromInputStream(is);
0
 
LVL 16

Author Comment

by:suprapto45
ID: 16569198
so how to get the properties in init method()?

properties.load(new FileInputStream([here is problem]));

David
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 1400 total points
ID: 16569234
properties.load(getClass().getResourceAsStream("rules.xml"));
0
 
LVL 16

Author Comment

by:suprapto45
ID: 16569250
That seems promising....give 15 mins to test

David
0
 
LVL 16

Author Comment

by:suprapto45
ID: 16569273
Sorry...be back on 30 mins
0
 
LVL 16

Author Comment

by:suprapto45
ID: 16569391
Hi CEHJ,

Sorry for that. It creates NullPointerException.

                        Properties properties = new Properties();
                        
                        properties.load(getClass().getResourceAsStream("ApplicationResources.properties"));

Am I in the right track? I thought that it should work

David
0
 
LVL 16

Author Comment

by:suprapto45
ID: 16569396
java.lang.NullPointerException
        at java.util.Properties$LineReader.readLine(Properties.java:365)
        at java.util.Properties.load(Properties.java:293)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16569406
Make sure it's in classes directory. Depending on the situation, it may need to be

properties.load(getClass().getResourceAsStream("/ApplicationResources.properties"));
0
 
LVL 16

Author Comment

by:suprapto45
ID: 16569407
Ah, that is my mistake.

After google it, I found that it should contain "/"
properties.load(getClass().getResourceAsStream("/ApplicationResources.properties"));

It works now. Thanks CEHJ

David
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16569435
:-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
A solution for Fortify Path Manipulation.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question