Hello, this may be alittle bit off topic, but I am not sure where to
post, so if you happen to know of a better place to find what I am
after please let me know.
My problem is that I have written a java application that lets the
user double click on a file and the program starts and loads the file.
To achive this I have wrapped the java app into a .exe file.
It all works, kind of. I set the file associations (windows as os btw)
during the installation. But what happens is that when the user double
click on a file the application starts with the directory of that file
as the "working directory". This causes problems for the applicaiton.
So I wonder is there a way to ensure that the working directory is
infact what we count on it to be?
I could run such code in the constructor or possibly even my main
method. Either way I need to make sure that the program starts in the
desired folder. Can I do this, and if so, how can I do this?
regards
Daniel
|
|
0
|
|
|
|
Reply
|
daik.no-spam (46)
|
12/7/2005 9:22:44 AM |
|
On Wed, 07 Dec 2005 10:22:44 +0100, Daniel
<daik.no-spam@mds.nospam.mdh.se> wrote, quoted or indirectly quoted
someone who said :
>This causes problems for the applicaiton.
>So I wonder is there a way to ensure that the working directory is
>infact what we count on it to be?
In windows you can create a "Shortcut" which specifies the exe, and
the working directory, and an icon. If the user clicks that instead,
you can set the working directory to what you want.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
|
|
0
|
|
|
|
Reply
|
my_email_is_posted_on_my_website (4730)
|
12/6/2005 11:32:38 PM
|
|
> To achive this I have wrapped the java app into a .exe file.
The solution might be in the way you wrapped your java app.
Could you please explain a bit how do you achieve the wrapping?
Regards
|
|
0
|
|
|
|
Reply
|
jfbriere (107)
|
12/7/2005 5:21:26 AM
|
|
Daniel wrote:
> during the installation. But what happens is that when the user double
> click on a file the application starts with the directory of that file
> as the "working directory". This causes problems for the applicaiton.
Rewrite your java application so that it does not depend on the current
working directory in order to function. Such application behavior is
almost always a bug.
Use mechanisms like Class.getResource()/Class.getResourceAsStream() in
case your application needs to find its own components, e.g. icons.
Use configuration data, e.g. via the Preference API (or Properties), and
provide a means to set this configuration data, in case the application
needs to know files, directories, locations, etc. outside its own realm.
Use the configuration data to form absolute pathes to files in case you
need to be sure that you really get a particular file.
> So I wonder is there a way to ensure that the working directory is
> infact what we count on it to be?
There is nothing Java can do about this. It is your operating system
which decides to change the working directory, not Java. Java does not
provide an API to change the current working directory, since the
concept of a current working directory does not even exist on all
operating systems. You can get the working directory via the system
property "user.dir", but that's all about it.
> I could run such code in the constructor or possibly even my main
> method. Either way I need to make sure that the program starts in the
> desired folder. Can I do this, and if so, how can I do this?
You are approaching the problem from the wrong end. Fix your application.
/Thomas
--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
|
|
0
|
|
|
|
Reply
|
nobody89 (1419)
|
12/7/2005 8:27:34 AM
|
|
"Daniel" <daik.no-spam@mds.nospam.mdh.se> schrieb im Newsbeitrag
news:9d9dp117ihlemkr66uma4uhvt3tois3dli@4ax.com...
> during the installation. But what happens is that when the user double
> click on a file the application starts with the directory of that file
> as the "working directory". This causes problems for the applicaiton.
> So I wonder is there a way to ensure that the working directory is
> infact what we count on it to be?
Can you modify the application? Actually it should not be a problem for the
application itself to run with a different "current directory".
If it is and you cannot change it, then you better let your users know the
application has such restrictions and they have to start it via a shortcut.
Anyway you have an installation procedure, so that one can create the
shortcuts as well.
Hiran
|
|
0
|
|
|
|
Reply
|
Hiran.Chaudhuri (21)
|
12/7/2005 8:43:45 AM
|
|
>On Wed, 07 Dec 2005 10:22:44 +0100, Daniel
><daik.no-spam@mds.nospam.mdh.se> wrote, quoted or indirectly quoted
>someone who said :
>
>>This causes problems for the applicaiton.
>>So I wonder is there a way to ensure that the working directory is
>>infact what we count on it to be?
>
>In windows you can create a "Shortcut" which specifies the exe, and
>the working directory, and an icon. If the user clicks that instead,
>you can set the working directory to what you want.
yes, BUT the problem is that the user is not starting the program via
a shortcut, but rather by clicking on a file associated with the
program (very much the same way that you double click a .html file and
firefox starts..). Unfortunatley I can not make the association to a
shortcut and have the shortcut set the starting dir. So the problem
remains.
I briefly thought about putting the installed dir in the a Preferences
node and on startup just set user.dir to that, but I am not sure that
would actually solve the problem. I did try to set it to something
absurd, but the program did it's checks for dependecies and they all
passed. So that means that if I can't just change the user.dir and it
will work.
regards
Daniel
|
|
0
|
|
|
|
Reply
|
daik.no-spam (46)
|
12/7/2005 10:50:32 AM
|
|
> I doubt the wrapping is the problem. None the less. I used launch4j
On the contrary since JAVA would not help you for this kind of thing.
With launch4j, there is an option to change current directory to the
executable location.
Did you set it?
Regards
|
|
0
|
|
|
|
Reply
|
jfbriere (107)
|
12/7/2005 5:40:07 PM
|
|
>> To achive this I have wrapped the java app into a .exe file.
>
>The solution might be in the way you wrapped your java app.
>Could you please explain a bit how do you achieve the wrapping?
I doubt the wrapping is the problem. None the less. I used launch4j
(available from sourceforge) with just plain vanilla settings. Nothing
strange, nothing changed so to say.
regards
Daniel
|
|
0
|
|
|
|
Reply
|
daik.no-spam (46)
|
12/7/2005 7:51:29 PM
|
|
Yeah, I guess you were right. Trying to fix this the easy way may just
prove to be the stupid way (it most often is actually...). I guess I
was just looking for the easy way out. oh well.
regards
Daniel
>Daniel wrote:
>> during the installation. But what happens is that when the user double
>> click on a file the application starts with the directory of that file
>> as the "working directory". This causes problems for the applicaiton.
>
>Rewrite your java application so that it does not depend on the current
>working directory in order to function. Such application behavior is
>almost always a bug.
>
>Use mechanisms like Class.getResource()/Class.getResourceAsStream() in
>case your application needs to find its own components, e.g. icons.
>
>Use configuration data, e.g. via the Preference API (or Properties), and
>provide a means to set this configuration data, in case the application
>needs to know files, directories, locations, etc. outside its own realm.
>Use the configuration data to form absolute pathes to files in case you
>need to be sure that you really get a particular file.
>
>> So I wonder is there a way to ensure that the working directory is
>> infact what we count on it to be?
>
>There is nothing Java can do about this. It is your operating system
>which decides to change the working directory, not Java. Java does not
>provide an API to change the current working directory, since the
>concept of a current working directory does not even exist on all
>operating systems. You can get the working directory via the system
>property "user.dir", but that's all about it.
>
>> I could run such code in the constructor or possibly even my main
>> method. Either way I need to make sure that the program starts in the
>> desired folder. Can I do this, and if so, how can I do this?
>
>You are approaching the problem from the wrong end. Fix your application.
>
>/Thomas
|
|
0
|
|
|
|
Reply
|
daik.no-spam (46)
|
12/7/2005 7:53:28 PM
|
|
Daniel wrote:
> Yeah, I guess you were right. Trying to fix this the easy way may just
> prove to be the stupid way ..
From my understanding of the problem requirements (file associations,
..exe's and Java application resources) JWS whould be a 'good way'.
Once JWS has delivered it all to the client, you can simply
Class.getResource() your .exe/.dll.
HTH
--
Andrew Thompson
physci, javasaver, 1point1c, lensescapes - athompson.info/andrew
|
|
0
|
|
|
|
Reply
|
SeeMySites (3836)
|
12/8/2005 12:31:30 AM
|
|
Daniel wrote:
> Hello, this may be alittle bit off topic, but I am not sure where to
> post, so if you happen to know of a better place to find what I am
> after please let me know.
> My problem is that I have written a java application that lets the
> user double click on a file and the program starts and loads the file.
> To achive this I have wrapped the java app into a .exe file.
> It all works, kind of. I set the file associations (windows as os btw)
> during the installation. But what happens is that when the user double
> click on a file the application starts with the directory of that file
> as the "working directory". This causes problems for the applicaiton.
> So I wonder is there a way to ensure that the working directory is
> infact what we count on it to be?
> I could run such code in the constructor or possibly even my main
> method. Either way I need to make sure that the program starts in the
> desired folder. Can I do this, and if so, how can I do this?
>
> regards
> Daniel
If I got it right, you need to know the complete path to the directory
where your .class file is.
I do it that way (assuming this code is in class MyClass in package
mypackage:
private String getFullPath() {
ClassLoader loader = ClassLoader.getSystemClassLoader();
String sep = System.getProperty("file.separator");
String clss = "mypackage" + sep + "MyClass.class";
URL url = null;
try {
url = loader.getSystemResource(clss);
} catch(Exception e) {
e.printStackTrace();
}
return (url != null ? url.getPath() : new String());
}
Is it what you need?
Francesco
|
|
0
|
|
|
|
Reply
|
Francesco
|
12/8/2005 10:10:29 AM
|
|
In a way that is what I am trying to achive. I had not thought of
going that way to find it but was considering using the Preferences
node to set the path during installation and then during execution
just get it out of the Preferences node. I will consider this and see
if it does indeed solve my problem.
thank you
>Daniel wrote:
>> Hello, this may be alittle bit off topic, but I am not sure where to
>> post, so if you happen to know of a better place to find what I am
>> after please let me know.
>> My problem is that I have written a java application that lets the
>> user double click on a file and the program starts and loads the file.
>> To achive this I have wrapped the java app into a .exe file.
>> It all works, kind of. I set the file associations (windows as os btw)
>> during the installation. But what happens is that when the user double
>> click on a file the application starts with the directory of that file
>> as the "working directory". This causes problems for the applicaiton.
>> So I wonder is there a way to ensure that the working directory is
>> infact what we count on it to be?
>> I could run such code in the constructor or possibly even my main
>> method. Either way I need to make sure that the program starts in the
>> desired folder. Can I do this, and if so, how can I do this?
>>
>> regards
>> Daniel
>
>If I got it right, you need to know the complete path to the directory
>where your .class file is.
>I do it that way (assuming this code is in class MyClass in package
>mypackage:
>
>
>private String getFullPath() {
> ClassLoader loader = ClassLoader.getSystemClassLoader();
> String sep = System.getProperty("file.separator");
> String clss = "mypackage" + sep + "MyClass.class";
> URL url = null;
> try {
> url = loader.getSystemResource(clss);
> } catch(Exception e) {
> e.printStackTrace();
> }
> return (url != null ? url.getPath() : new String());
>}
>
>
>Is it what you need?
>
>Francesco
|
|
0
|
|
|
|
Reply
|
daik.no-spam (46)
|
12/9/2005 6:16:03 AM
|
|
|
11 Replies
35 Views
(page loaded in 0.124 seconds)
Similiar Articles: problems with loading module to SystemSymbolTable - comp.os ...... path[128]; > > =A0 =A0 =A0 =A0 strncpy(pctrl_path, "\0", 128); > > =A0 =A0 =A0 =A0 sprintf(pctrl_path,"%spctrl.out", usr_dir); > > > =A0 =A0 =A0 =A0 printf("Starting ... need help with corrupt MAIL.MAI file - comp.os.vmsYesterday, I did MAIL> DIR MAIL/START=99999 and didn't see, as expected, some recent messages, but rather the last one was from 13-SEP-2009. find files between date x and date y - comp.unix.solaris ...On to find, you can find -newer and then ! -newer, like this: $ find /dir -newer start_date ! -newer stop_date -print Combine that with ls -l, you get: $ find /dir ... Using awk to find a range of dates - comp.lang.awk... from=20030731 aprefix* to=20030701 bprefix* that would get all the files starting with ... awk -v from="June 1, 2002" -v to="July 31, 2002" -f scriptfile /path/to/dir ... input & output in assembly - comp.lang.asm.x86... NumberOfRvaAndSize (entries ; in the data dir) ; ..... ; : Start of Image ... Could anyone give me the spice-mode.el - comp.emacsHi, All I am new to *NIX and I am thinking of writing spice code under Emacs. However, I have no idea of Emacs Lisp. Hence, I could not write a packa... How clear console using java - comp.lang.java.programmer ...try { Process dir = Runtime.getRuntime().exec("cls ... error=2,The system cannot find the file specified at java.lang.ProcessBuilder.start ... Directory creation and file moving by modification dates? - comp ...Something like (assuming you have GNU stat) cd /photo/dir for f in *.jpg; do ... d" mv -- "$f" "$d"/"$f" done It creates a directory tree starting with ... ssh remote execution - comp.unix.programmerI wrote a program which create a sub-process the sub-process will then start another ... call after I fork another process > > execl("/bin/ssh","ssh","user@host","~/dir ... Nonlinear brick wall filters - comp.dspAlternately: 1) Start with the same filter. 2) Convolve the filter impulse response with 0.5*Dir(-T)+Dir(0)+Dir(+T) where T is the frequency sampling interval and "Dir ... Can't connect to local MySQL server through socket '/var/mysql ...I got this error starting mysql from installation: sh-3.2# /usr/local/mysql/bin/mysql ... roughs-power-mac- g5.lower-test ^G/usr/local/mysql/bin/mysqld: Can't change dir ... analyze core files - comp.unix.solaris... which I want to analyse and when I give arguments like below ../viewldbg "HOME_DIR ... How to analyze core files? > > Please help > Thanks start with gdb /path/to/ns-slapd ... Setting the working directory of an eclipse rcp application - comp ...Hi,I'm working on a eclipse rcp application. Everything is fine so far,unless i start trying to export my application. Unfortunatelly i haveto change ... ERROR 2006 (HY000): MySQL server has gone away - comp.databases ...... MySQL Server 5.0\bin\mysqld-nt: Normal shutdown 070427 17:09:21 InnoDB: Starting ... sure you don't have any corruption in any of your data files ( >> in the data dir ... Sockets in gfortran? - comp.lang.fortranI think you want to start thinking along these lines. I follow the Stevens and Rago ... returns */ dopath(Myfunc* func) { struct stat statbuf; struct dirent *dirp; DIR ... List words starting with dir - More Words - Search Dictionary ...List all words starting with dir. 83 words found. dirdum dirdums dire direct directed directedness directednesses Starting StrengthRip interviews Marty Gallagher - lifter, writer and coach of champions. Part 1 Part 2:: Discuss in Forum. Entry 1 of 151 1 2 3 > Last › 7/24/2012 1:55:05 AM
|