cancel
Showing results for 
Search instead for 
Did you mean: 

How to find path of a file in WebDynPro Application

aayush_dubey3
Explorer
0 Kudos

Hello,

I have created a WebDynPro application. In this application i have created an XML file under

src->packages->resources. The resources folder i created myself.

I have also deployed the file on a remote server. This servername & portNumber can change too.

Now i want to get the handle of my XML file (which is present in the same jar) so that i can user it and populate it.

<b>The following code doesnt work:</b>

<i>File file =new File("WebDynProProjectName/resources/filename.xml");</i>

Regards,

Aayush

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

Hi all,

I too had the same issue.. Now could able to solve that.. Thanks to all of you..

Former Member
0 Kudos

I am following the instructions for adding just a txt file to src\mimes\Components\<Component name>\file.txt and when i try to create a new File(file.txt) I get a FileNotFoundException. Why?

Thanks...

Former Member
0 Kudos

The constructor new File("file.txt") throws a FileNotFoundException? Don't think so.

Can you please post your code?

Armin

Former Member
0 Kudos

sorry what i meant was using FileReader(file.txt). this is what the actual code looks like. Nothing exciting just trying to get the file:

FileReader fr;

try

{

fr = new FileReader("deviceTypes.txt");

BufferedReader br = new BufferedReader(fr);

String type = br.readLine();

while(type != null)

{

type = br.readLine();

}

}

catch(FileNotFoundException fnfe)

{

}

Former Member
0 Kudos

What is the output of

File file = new File("deviceTypes.txt");
wdComponentAPI.getMessageManager().reportSuccess(file.getAbsolutePath());

assuming you are calling this from within a controller method.

Armin

Former Member
0 Kudos

i'm calling this in a view actually. this is what i get back when i catch the exception and call getAbsolutePath(): "Exception: deviceTypes.txt (The system cannot find the file specified)FilePath: C:\usr\sap\WHE\JC00\j2ee\cluster\server0\deviceTypes.txt"

Former Member
0 Kudos

Ok. If you use


String path = WDURLGenerator.getResourcePath
(
  wdComponentAPI.getDeployableObjectPart(),
  "deviceTypes.txt"
);
wdComponentAPI.getMessageManager().reportSuccess(path);

what do you get?

What is the location of your file on the server?

Armin

Former Member
0 Kudos

this is what i get:

.\temp\webdynpro\web\local\xDemo\Components\xdemo.TestApp_WD\deviceTypes.txt

but, if i actually pass it the path it works though and when i just pass deviceTypes.txt it doesn't.

try

{

String path = WDURLGenerator.getResourcePath

(wdComponentAPI.getDeployableObjectPart(),

"deviceTypes.txt");

FileReader fr = new FileReader(path);

BufferedReader br = new BufferedReader(fr);

String type = br.readLine();

...

}

Former Member
0 Kudos

Have a look at the WDURLGenerator API.

Armin

Former Member
0 Kudos

Hi Aayush,

You can place your all required external files in src/mimes/components/<comp name>.

For this oopen the node src in webdynpro explorer and follow the above path. then right click on your component under this path and choose import files.

Then choose your XML file.

It will export this file in your component folder.

And now from your code you need not to give any explicit path or relative path to this file.

Only you need to give file name, thats it.

Let me know whether it qworks for you or not.

Regards,

Bhavik

aayush_dubey3
Explorer
0 Kudos

Thanks Anilkumar, Bhavik,

Will try today and let you know if it solves the problem.

Regards,

Aayush

Former Member
0 Kudos

Hi Aayush ,

1. Copy the file under Project/Src/Mimes/Components/<<ComponentName>>/Test.xml

2. Read the file using File file =new File("Test.xml");

This should solve the problem.

Regards, Anilkumar

Former Member
0 Kudos

Hi

By default it puts it under resources folder. If you want to create your own path then

1. Create the XML file (eg. output.xml) to some location in the server (eg: c:\Test\files)

2. Create a HTTP alias(eg. Test) in the Visual Adminsitrator pointing to the file location (eg: c:\Test\files).

3. Set the linkToURL reference property to http://<<servername>>:50000/Test/<<XML file name>>

For creating the HTTP alias refer to the blog "Creating an HTTP Alias in WAS"

/people/renjith.andrews/blog/2005/03/31/creating-an-http-alias-in-was

Hope this solves your problem.

regards

Ravi

aayush_dubey3
Explorer
0 Kudos

Hello Ravi,

Thanks. But this does not solves my problem :-(.

As of now i am just creating the project and building it in my development environment. I do not know about the runtime environment details as of now.

I can make it run only on 1 server using HTTP alias but i want to ensure that my utility (jar file) when deployed on any server uses the XML file packed with it.

Regards,

Aayush