Results 1 to 16 of 16
- 06-21-2011, 01:47 PM #1
Member
- Join Date
- Jul 2010
- Location
- Hyderabad
- Posts
- 21
- Rep Power
- 0
How to load drl file dynamically within the Application
Hi,
I am developing one project.In that i created different packages.Each packages has lot of java files..
What i am doing is,i want to load a drl file dynamically from java class..That file is somewhere in the project.
My problem is,if i do in this way then i am getting null pointer exeception..that means that file is not loaded...
i used the following piece of code..
InputStream in=this.getClass().getClassLoader().getResourceAsS tream(" drl file name");
InputStream in=Thread.currentThread().getContextClassLoader(). getResourceAsStream("drl file name");
But both statements are not working....please anybody help me...
Thanks in advance
Prasad.vara
- 06-21-2011, 02:54 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Where is that file?
Why are you using getClassLoader?
Why not simply use the getResourceAsStream() method on Class?
- 06-21-2011, 03:16 PM #3
Member
- Join Date
- Jul 2010
- Location
- Hyderabad
- Posts
- 21
- Rep Power
- 0
Hi,
All drl files are in com.abc.drl package... in cofig folder
My current java class is in com.main.javafiles package... in src folder
I used the simply this.getClass().getResourceAsStream() also...it also not working..
Thanks...
- 06-21-2011, 03:29 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Is the config folder on your path?
(That will depend on what IDE you're using).
If so then your file is "/com/abc/drl/<filename>", for the purposes of getResourceAsStream()...the one from Class that is.
- 06-21-2011, 03:34 PM #5
Member
- Join Date
- Jul 2010
- Location
- Hyderabad
- Posts
- 21
- Rep Power
- 0
yes.I have set the classpath for both src and config folders...I am using eclipse IDE..
- 06-21-2011, 03:40 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
And that applies to runtime as well?
And did you use the file string I supplied, with the full path (and leading slash)?
- 06-21-2011, 03:51 PM #7
Member
- Join Date
- Jul 2010
- Location
- Hyderabad
- Posts
- 21
- Rep Power
- 0
i put only file name not full path even leading slash also...
code is like as:
getResourceAsStream("mytest.drl");
file name is :mytest.drl
this is in package com/abc/drl/mytest.drl
- 06-21-2011, 04:05 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Which is why it doesn't work.
Have you tried with the full path name as I suggested?
- 06-22-2011, 01:23 PM #9
Member
- Join Date
- Jul 2010
- Location
- Hyderabad
- Posts
- 21
- Rep Power
- 0
if i try with the full path then it is working fine...But i want to load it by providing the file name only not full path...
So, if i do as explained before then it is not working...can we load it by providing the file name only?
- 06-22-2011, 01:36 PM #10
The file name only should work if the file is in the 'current directory' when the program executes.
I have no idea where the current directory is when executing inside of an IDE.
Create a File object and print out its absolute path:
Java Code:File testFile = new File("Here"); System.out.println("apPath=" + testFile.getAbsolutePath()); //apPath=D:\JavaDevelopment\Testing\ForumQuestions5\Here
- 06-22-2011, 01:37 PM #11
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
- 06-22-2011, 02:01 PM #12
Member
- Join Date
- Jul 2010
- Location
- Hyderabad
- Posts
- 21
- Rep Power
- 0
This time, I am using only one package( which contains drl files).In future, it will happen that using more than one package... Then we don't know that we can load which drl file from which package...That is why, I try to load the drl file with only file name not with full path..
Thanks in advance.
- 06-22-2011, 02:07 PM #13
If you put the file in a package, then you'll need to use that to find the file.
If the code that is trying to read the file is in the same package as the file, it may be able to read it with only the filename. Write a small simple program to test this.
- 06-22-2011, 02:09 PM #14
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
- 06-22-2011, 02:19 PM #15
Member
- Join Date
- Jul 2010
- Location
- Hyderabad
- Posts
- 21
- Rep Power
- 0
see the drl files have been divided to provide modularity for the project and have been put in more than one package. the task is to load the files from a class say RuleEngine, can u help me over this????
- 06-22-2011, 02:23 PM #16
Make a small test program with code in different packages that tries to read the file and print the first line of the file.
Create several files with the same name but different contents so they can be identified when they are read and the first line is printed. Put versions of the files in all the folders corresponding to the packages.
Execute the code and see what is printed out.
Similar Threads
-
How can i execute one java file(dynamically created) from the other
By Rak239 in forum New To JavaReplies: 1Last Post: 11-03-2009, 07:07 AM -
retain value of input type file in a jsp file while being dynamically generated
By nidhi c in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 09-27-2009, 02:21 AM -
loading .properties file dynamically
By nanaji in forum Advanced JavaReplies: 3Last Post: 03-17-2009, 03:40 AM -
Dynamically loading the jsp page to the application
By shekar in forum JavaServer Pages (JSP) and JSTLReplies: 3Last Post: 04-09-2008, 03:28 PM -
Launching an application from another application dynamically
By Java Tip in forum Java TipReplies: 0Last Post: 02-16-2008, 09:31 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks