aspose file tools*
The moose likes Applets and the fly likes copy file from init() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "copy file from init()" Watch "copy file from init()" New topic
Author

copy file from init()

bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
hi.

i have applet which uses dll file..
the dll file should be in system32 folder.

now,

when the client runs this applet, the dll should automatically should get copied in his system32 folder.( i suppose this coding should be in init() )


i used
this code
but this code is not copying the dll file when running the client in different system other than server.



any help please..


thanks in advance.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41793
    
  62
What is the value of "path"? You're not once again mixing server file system and client file system, are you?

Also, a directory named "C:\\j2sdk1.4.2_06" won't exist on most client systems, but I'm assuming you've considered that.

I'm not sure what you're trying to achieve, but copying native libraries is most likely not the best way to do it.


Ping & DNS - my free Android networking tools app
bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
hi ulf,

the value of the path is D:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\Samples
this is where all my files reside..

this path is in the server side.
the dll file (testall.dll) is also in this location ( other location is winnt\system32)

now i have tested that the testall.dll from the PATH is copied to that "C:\\j2sdk1.4.2_06\\testall.dll");
( this is when i run the server ans cllient on the same machine. i run it that way just to check the code to copy file is working )

but the real need is to copy the testall.dll from PATH to the clients c:\winnt\system32 folder

i tried to run the server on my machine and the client on other machine with the destination folder as c:\\winnt\\system32\\testall.dll , but it did not work. it when i started this thread.

i'm not messing up with server and client side file systems, i suppose.

i heard that we have to fetch the IP adress of the client and then copy the file to ipaddress\\c:\\winnt\\system32\\testall.dll
i do not know if it is correct.

any help please..

thanks in advance
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41793
    
  62
i'm not messing up with server and client side file systems, i suppose.

You suppose wrong - you ARE using a server path on a non-server machine. We've gone over why this doesn't work repeatedly; no need to do it again.

If the server directory where the DLL resides is accessible through SMB, then you can use the http://jcifs.samba.org/ library to do the file copying. No responsible system administrator will make a web app directory accessible that way, though, so the DLL would have to be moved to some publicly shared directory.
bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
hi ulf,

then what is the solution for this.
i need to download the file to the client machine ( it will be good if i do from init() ) at the run time.


thank you in advance


bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
hi,
in other words, how to download the dll file from server to client at run time.



thank you.
bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
hi,

i ask this because one of my colleague has done it ( he will run the client in any of the machines in our lab [ he runs the server on his machine ] and the client downloads the dll file and copies it to the system32 folder ). he extracts everything from me ( i mean he wants me to find everything by myself. he helps only if i become helpless. thats a god thing so that i can learn new things on my own and that's what he wants).

anyways, he has done it, so it is possible


thank you
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41793
    
  62
Of course it's possible, but not in the way you're trying to do it.

The best method by far is the one I mentioned in http://www.coderanch.com/t/456033/Applets/java/steps-run-applet, because that doesn't rely on the details of the client-side file system (no file copying and installation is required).

If the file is accessible through HTTP (which it would be if it's in webapps\Samples) then you can use an URLConnection from the applet to the server to read it, and then write it to whichever directory it should go.

If the file is accessible through SMB, then you can use the library I mentioned in my previous post. This is the method of last resort, though; I wouldn't recommend it.
bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
hi ulf,
thank you.


i got the info that my colleague was using nio api to do that.
so i'm trying with that.

inform you with any updates
bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
hi,


If the file is accessible through HTTP (which it would be if it's in webapps\Samples) then you can use an URLConnection from the applet to the server to read it, and then write it to whichever directory it should go.


can you tell me something on this procedure.

is this that you were talking about.



do not mistake me, what we are preparing is for the demo. there will be ample time before deployment. and my colleague also done this in the way i'm proceeding ( which you didn't recommend due to some system admin problems)

thank you in advance
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41793
    
  62
Yes, that's pretty much what I meant. The way to get the URL should be like this, though:

URL copyurl = new URL( getCodeBase() , "testall.dll" );

and the filename "testall.dll" should be a parameter passed in through the applet tag.

The big drawback of this technique is that there's really no way to know (unless you have specific knowledge of the client system) that "c:\\winnt\\system32" is the correct directory to copy the file into. Do all Windows machines have that directory? Also, what happens if the DLL needs to be updated? Sure, you can overwrite the file, but if it's loaded already then there's no way to unload it without rebooting the machine. All these problems (and more) are avoided by using the JNLPAppletLauncher technique.
bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
thank you ulf,

you are right, and when me and my colleague discussed about that jnlp earlier today, he too agreed with you and accepted that his method is not recommended. he made this stuff just to be ready for the demo, just in case if they want to see suddenly. we will work on jnlp for the future use( to avoid all those things you mentioned).

in the mean while in my java learning stages, i'm trying that same method by myself.

thank you..
i will update you on the result.
bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
hi ulf,

i used the following code

JSP



param in applet







but it did not work.......
in the client machine it is showing in the java console, testall ( my dll )was not found in java.lang.path
unsatisfiedlinkerror

thank you in advance.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

Given that your applet has permission to actually write the DLL to the client -- which it of course won't, unless you have dealt with this by digitally signing the applet and asking for appropriate permissions -- this should probably write the DLL. Be sure to check the "Java Console" in the browser for stack traces, as you're not reporting problems any other way.

Given that this works, then the next question is when and how are you trying to load the DLL? If it's in a static initializer for the applet itself, this won't work, of course -- the applet class is already loaded, and the DLL noted as missing, by the time the DLL is actually available.


[Jess in Action][AskingGoodQuestions]
bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
Hi ernest,

this is my error



i will load the dll only on the actionperformed event and not before that.

thank you in advance
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41793
    
  62
testapp.init(testapp.java:66)

This looks like you're trying to load the library in the init() method; what's line 66 do?

Is the c:\\winnt directory (where the code is writing the file) part of the PATH of the client machine?
bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
hi ulf,


this is line 66



the testall class contains these kind of stuff




this line has nothing to do with the client.



thank you in adavance
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41793
    
  62
this is line 66


And that's called before or after the code you posted above? As Ernest said, if it's called before then it can't work.

Have you made sure that c:\\winnt is part of the PATH?
bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
hi ulf,

it is before the code i posted..
and

And that's called before or after the code you posted above? As Ernest said, if it's called before then it can't work.

is this what ernest said, i'm sorry, i did not understand that.


and one more doubt ulf,

do i need to copy all the files which are associated with this file,
i mean testall.java, as i have poted in the last post.. my class calls that class as well.

thank you in advance

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41793
    
  62
it is before the code i posted..

How could it possibly work to call a native library before you transfer that library to the machine where it's supposed to run?

i mean testall.java, as i have poted in the last post.. my class calls that class as well.

Since the stack trace includes a mention of the class "testall", it would seem that it already is where it needs to be.
bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
thank you ulf,


it worked perfectly..

thank you very much
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: copy file from init()