System.getProperty("user.dir") returns "/home/user" on Linux
Has anyone else had the error when launching a jar from Linux (just by clicking it), System.getProperty("user.dir") returns the "/home/user" (or "~") value instead of the folder that the jar is in? Essentially, it returns "user.home" instead of "user.dir".
This does not happen when I start the application from command line.
(I know its not swing, but I wasn't sure where to post it)
Is this just a simple Linux setting that isn't enabled by default? Ubuntu already made the file association after using apt-get to install Java 6.
Cheers.
-FBL
Because, semmingly, the command is being set off as
java -jar relative/pat/to/file.jarwhen you double click it, rather than
cd relative/path/to
java -jar file.jarIf you don't like this, I would say to find a Linux, preferably Ubuntu, forum and ask there if it is possible to change that handling, and if not, request that a cahnge be made to the code to change that handling. But, in any case, I doubt you are going to get an answer here about it.
Similar Messages
-
System.getProperty("user.dir") different in Ubuntu?
HI. I have this application which when the user presses the Help button an HTML user guide is shown.
this is done using:
String userDir = System.getProperty("user.dir");
System.out.println(userDir);
Desktop d = Desktop.getDesktop();
File f = new File(userDir);
URI u = new URI(f.toURI().toString()+"User_Guide/index.htm");
System.out.println(u.toString());
d.browse(u);This works on Windows machines, but when tested on Unix Ubuntu the user guide does now show.
The System.getProperty("user.dir") returns users/j/john/ which is not the complete directory. How can I fix this so that the Help button works on both platforms?Thanks!
Edited by: player123 on Jun 9, 2009 10:54 AM++
Make sure its Sun's Java no OpenJDK or others.
$ java --version
also echo $JAVA_HOME
it depends how its linked on yours.
Even if you install the Sun's JDK you must properly link it and/or set and export its home ;) -
System.getProperty("user.dir") cannot rerturn the package directory.
i have a class belong to package suyuan
the class file is located at
D:\Profiles\cyc025\Desktop\suyuan\test.class
i try to execute System.getProperty("user.dir") inside test.class.
i get D:\Profiles\cyc025\Desktop
but i wish there is a java api which can return
D:\Profiles\cyc025\Desktop\suyuan
how can i do so?
thank you.
regards
yan chengThe system property "user.dir" returns the current working directory. The "suyuan" is a part of the java package of test.class - it has nothing to do with each other. If you want your string you need to create it via
String pn = getClass().getName();
int i = pn.lastIndexOf('.');
pn = pn.substring(0, i);
String mine = System.getProperty("user.dir") + File.separatorChar + pn; -
System.getProperty doesnot work
Hi,
I have a piece of code where I try to get a env variable VTNAME in my java application. Code snippet below
//this function creates a session.
public void setSession(configParams params) throws Exception {
boolean done = false;
int retryCount = 0;
mVTName = params.getFactoryName();
System.out.println(System.getProperty("VTNAME"));
It returns me null. And when i do
:/home/santsat > echo $VTNAME
dbusd1.srv.uk.deuba.com:8092/tcp:
Any thoughts o what is wrong in the code?
Thanks
Message was edited by:
chabhiJava's system property is not the same as environment variable.
To get environment variable, use System.getenv().
If you start your java app with -DVTNAME= then you can use System.getProperty().
Budyanto -
Alternative to System.getProperty("microedition.hostname")
Hey is there any other alternative for 'System.getProperty("microedition.hostname")' to get the ip address of the device running the j2me midlet ??
When you run the midlet on the emulator, System.getProperty("microedition.hostname") returns the PC's Name, but on a Nokia series 40(3rd E) device, it returns null.
So is there an alternative to this to select the device's ip address ?First this is a pretty specific question which applies to a specific device rather than to reflection/reference. You might want to look for a forum that addresses the specific device.
Second, you can print the system properties normally. Whether you can do that on the device depends on the device. If you succeed you might find an alternative.
Third normally one uses the java.net.IpAddress to get a device IP. Does that not work for that device? -
System.getProperty("user.home") is giving diferent results on diff versions
I am working on windows 2000. When I try to get user.home using System.getProperty it gives me c:\documents and settings\my name.
But the same things when tried on a windows 2003 server tries to look in c:documents and settings\default directory. Why is this?
Please help.....In XP, the environment variable USERPROFILE is set to C:\Documents and Settings\<username>, and that value is picked up for user.home. Since the "user's home directory" varies by os, there will be variations. 98 is different than Linux than XP, etc.
-
Dear all,
I'm having trouble getting the system property user.name (which we need in our ant scripts) on our CentOS box. :(
When running the program below thru
java dumpproperties2
it prints "user.name='?'" on our CentOS 4.3. On win32 it works. It turns out that if you add the account corresponding to the EUID to /etc/passwd it works correctly. However, we don't use passwd authentication but an enterprise wide LDAP-system. Our /etc/nsswitch.conf says:
passwd: files ldap
One work around is to replace the java executable with a script that does
/path/to/jdk/bin/java -Duser.name=$USER -Duser.home=$HOME $@
Used jdk is j2se 1.5.0_13 Linux 32-bit.
Some questions for the experts:
1) Is there any other way?
2) Is it a known issue that Linux versions of the jdk just looks in /etc/passwd to map uid to user name (and home dir) instead of doing what the rest of the system, like whoami, does? I haven't found anything in either the readme or installation instructions, nor in the bug db.
Br, Jesper Tr�g�rdh
public class dumpproperties2 {
public static void main(String[] args) {
String s = System.getProperty("user.name");
System.out.println("user.name='" + s + "'");
}Does this work?
//public final class System
public static String getenv(String name)Then you can access the USER environment from inside Java. -
GetProperty("user.dir") Causing Exception
I'm using the System.getProperty("user.dir") command to identify the current directory within Unix.
Running the program within the directory it was compiled works great, but run it from anyother directory causes the following error
Exception in thread "main" java.lang.NoClassDefFoundError: SortFiles
Any ideas why ?
Thanks
class SortFiles {
public static void main(String[] args) {
String path = System.getProperty("user.dir");
System.out.println(path);The error is nothing to do with System.getProperty()
The error is thrown by the JVM because it can't find your class to begin with, it's not getting as far as your code because it cannot find it.
Set your classpath (or use the -cp option) to run your class.
System.getProperty("user.dir") should then return the director you ran your program from. -
Is there a System.getProperty("user.desktop")
I am trying to get the path of a user's desktop, regardless of OS.
I know that I can use
System.getProperty("user.home")to get the current user's directory, but what about the current user's desktop? is there a call for that?
if not, i know where the windows desktop folder is located, but I am unfamiliar with Mac, Linux, other Unix OSs...could anyone please share where their desktops are from the root dir?
thanks.Two suggestions so far for Linux:
* /usr/local/foo
* user.home
The first will probably only be writable if your installer* is being run by root / superuser. I'd say that the expected behaviour would be to extract to pwd - i.e. user.dir. However, as already stated I'd quite like to be given the choice first if it's a GUI installer. A console installer which extracts to pwd would seem quite reasonable.
Of course, you could take the view that most Linux users are used to getting a .tgz which they then extract whereever they want, so if your jar contains the file it extracts it's probably sufficient to put a README.txt in it and prompt the Linux user to read it.
Under OS X people will probably expect you to use the built-in installer. You might be able to build a suitable package without an OS X box - check Apple's website for documentation. The desktop is ~/Desktop (where ~ is user.home).
* If it's not an installer, although you seem implicitly to have agreed it is, I'd extract to /tmp/fooRND, making sure that it didn't exist and generating a new RND if it did. -
How to restrict "sftp only" user into your home dir and subdir
Hi OTN forums members
Question : I want restrict a sftp only user to browse ONLY in your home directory and subdirectory . I don't want sftp user access into other directory.
Details : I want use a "ssh bundle package" on s10(only package on SUNWCXall installation cluster). I don't want to use the "extrernal package", as "ProFTP", "Chroot", sunfreeware OpenSSH package,ecc. It's possible?
Technical Details of my system(test) : the hostname and username it's fantasy name, not real ;-)
root@sunlab1:/[1]$ cat /etc/release
Solaris 10 5/09 s10s_u7wos_08 SPARC
Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
Use is subject to license terms.
Assembled 30 March 2009
root@sunlab1:/[2]$ uname -a
SunOS sunlab1 5.10 Generic_142909-17 sun4u sparc SUNW,Sun-Blade-100
root@sunlab1:/[3]$ grep explorer /etc/group
explorer::111:
root@sunlab1:/[4]$ grep explorer /etc/passwd
explorer:x:111:111:Sun Explorer Data Collector sftp only user:/export/home/explorer:/usr/lib/ssh/sftp-server
root@sunlab1:/[5]$ zfs list
NAME USED AVAIL REFER MOUNTPOINT
rpool 27.3G 9.33G 96K /rpool
rpool/ROOT 11.6G 9.33G 18K legacy
rpool/ROOT/s10s_u7wos_08 11.6G 9.33G 11.6G /
rpool/cfengine 73.7M 950M 73.7M /var/cfengine
rpool/dump 1.00G 9.33G 1.00G -
rpool/export 5.01G 9.33G 11.8M /export
rpool/export/home 1.40G 3.60G 1.40G /export/home
rpool/mp3 2.65G 2.35G 2.65G /mp3
rpool/patches 206M 2.80G 206M /var/patches
rpool/swap 768M 9.58G 514M -
root@sunlab1:/[6]$
root@sunlab1:/[7]$ cd /export/home
root@sunlab1:/export/home[9]$ ls -la
total 47
drwxr-xr-x 5 root root 9 Oct 7 09:51 .
drwxr-xr-x 4 root sys 6 Jun 7 09:44 ..
drwxr-x--- 11 explorer explorer 11 Oct 7 11:30 explorer
root@sunlab1:/[8]$ sftp explorer@sunlab1
Connecting to sunlab1...
Password:
sftp> dir
[...more output...]
sftp> pwd
Remote working directory: /export/home/explorer
sftp> cd /var/adm
sftp> dir
[...more output...]
sftp> get messages
Fetching /var/adm/messages to messages
sftp> pwd
Remote working directory: /var/adm
sftp> bye
root@sunlab1:/[9]$
root@sunlab1:/[10]$ pkginfo -l SUNWsshr
PKGINST: SUNWsshr
NAME: SSH Client and utilities, (Root)
CATEGORY: system
ARCH: sparc
VERSION: 11.10.0,REV=2005.01.21.15.53
BASEDIR: /
VENDOR: Sun Microsystems, Inc.
DESC: Secure Shell protocol Client and associated Utilities
[...snip...]
root@sunlab1:/[11]$ pca -l installed --pattern=[Ss]sh
[...snip...]
Using /var/patches/pca/patchdiag.xref from Oct/14/10
Host: sunlab1 (SunOS 5.10/Generic_142909-17/sparc/sun4u)
List: installed (3/584)
Patch IR CR RSB Age Synopsis
141742 04 = 04 -S- 427 Obsoleted by: 141444-09 SunOS 5.10: sshd patch
143140 04 = 04 RS- 119 Obsoleted by: 143559-03 SunOS 5.10: ssh patch
143559 03 = 03 RS- 38 SunOS 5.10: ssh scp patch
root@sunlab1:/[12]$ pca -l 141444 143559
Using /var/patches/pca/patchdiag.xref from Oct/14/10
Host: sunlab1 (SunOS 5.10/Generic_142909-17/sparc/sun4u)
List: 141444 143559 (2/405)
Patch IR CR RSB Age Synopsis
141444 09 = 09 RS- 367 SunOS 5.10: kernel patch
143559 03 = 03 RS- 38 SunOS 5.10: ssh scp patch
root@sunlab1:/[13]$Legenda:
PCA = [url http://www.par.univie.ac.at/solaris/pca/] Patch Check Advanced , PCA is 3PP free and fast tool for Analyze, download and install patches for Solaris
IR =Installed Rev. CR = Current Rev. (published on patchdiag.xref from Oct/14/10)
RSB =[R]eccommended,[S]ecurity, [\B]ab patches
Not helpful reading "<tt>man sshd_config</tt>" and "<tt>man sftp-server</tt>", and Google searching. Nothing by MOS Community search.
Any idea?
Best Regards
Michele V.
P.S.: Excuse me for my bad English.Hi OTN forums members,
I find the solution. Thanks Andrea Manganaro (aka Amanga) for the help.
1) Download and install OpenSSH for Solaris 10/SPARC and all dependencies(Please read the http://www.sunfreeware.com/openssh.html note):
- [url ftp://ftp.sunfreeware.com/pub/freeware/sparc/10/openssh-5.6p1-sol10-sparc-local.gz]openssh-5.6p1-sol10-sparc-local.gz
- [url ftp://ftp.sunfreeware.com/pub/freeware/sparc/10/openssl-1.0.0a-sol10-sparc-local.gz]openssl-1.0.0a-sol10-sparc-local.gz
- [url ftp://ftp.sunfreeware.com/pub/freeware/sparc/10/zlib-1.2.5-sol10-sparc-local.gz]zlib-1.2.5-sol10-sparc-local.gz
- [url ftp://ftp.sunfreeware.com/pub/freeware/sparc/10/libgcc-3.4.6-sol10-sparc-local.gz]ibgcc-3.4.6-sol10-sparc-local.gz
2) Configure <tt>/usr/local/etc/sshd_config</tt> file with the "+<tt>ChrootDirectory</tt>+" directive. For me:
# override default of no subsystems
#Subsystem sftp /usr/local/libexec/sftp-server
Subsystem sftp internal-sftp[...]
# Example of overriding settings on a per-user basis
Match Group sftponly
ChrootDirectory %h
ForceCommand internal-sftp
AllowTcpForwarding no3) Create group and user for sftp-only account. For me:
root@taurus # groupadd sftponly
root@taurus # grep sftponly /etc/group
sftponly::202:
root@taurus # useradd -g sftponly -c "Sftp only user" -d /export/home/explorer -s /bin/false -m explorer
explorer:x:1002:202:Sftp only user:/export/home/explorer:/bin/false
root@taurus # passwd explorer
New Password:
Re-enter new Password:
passwd: password successfully changed for explorer
root@taurus # 4) Change home directory permission and create a r/w direcorty (uploads) for sftponly user account.
root@taurus # cd /export/home
root@taurus # ls -la
total 14
drwxr-xr-x 4 root root 4 Oct 29 15:28 .
drwxr-xr-x 3 root sys 3 Jan 22 2009 ..
drwxr-xr-x 3 explorer sftponly 3 Oct 29 15:41 explorer
root@taurus # chown root:sftponly explorer; chmod 750 explorer
root@taurus # ls -la
total 14
drwxr-xr-x 4 root root 4 Oct 29 15:28 .
drwxr-xr-x 3 root sys 3 Jan 22 2009 ..
drwxr-x--- 3 root sftponly 3 Oct 29 15:41 explorer
root@taurus # This will make a read-only, chrooted directory perfect for people to come in and get stuff, but never write.
For example, you could make a directory explorer/uploads that allow people to write in.Then you can moderate what gets copied into the read-only /explorer area. Remember that if a user can write in a directory then they can also delete anything in that directory.
root@taurus # cd explorer
root@taurus # mkdir uploads && chown -R explorer:sftponly uploads && chmod 0755 uploads
root@taurus # ls -al
total 9
drwxr-x--- 3 root sftponly 3 Oct 29 15:41 .
drwxr-xr-x 4 root root 4 Oct 29 15:28 ..
drwxr-xr-x 2 explorer sftponly 2 Oct 29 15:56 uploads
root@taurus # 5) Disable SunSSH "service" and enable OpenSSH "service" (with SMF):
root@taurus # svcadm disable sshSee [url http://www.sunfreeware.com/sshsol10.html]here for Running openssh vis SMF on Solaris 10 Systems
root@taurus # svcadm disable ossh
root@taurus # svcs -a | grep ssh
disabled 12:37:51 svc:/network/ssh:default
online 15:29:41 svc:/network/ossh:default
root@taurus # 6) Test your job :-)
Helpful links:
==============
http://www.sunfreeware.com
http://www.openssh.org
http://calomel.org/sftp_chroot.html
HTH
Michele Vecchiato -
Hello,
Based on the user's requirements, I implemented authentication based on the results of the System.getProperty(user.name) feature. The audit group has some concerns on where the user.name value is coming from.
Does anyone have any idea where this property is coming from, and if it is coming from a file, whether it is stored as text.Environment variable that is read internally by the JRE. If you go to dos (in windows) and type "set" and hit return, you'll see Username=whatever your login name is. If course, someone with the right credentials can change this.
Unix has a similar feature. -
Document Management Systems for Home User
Hello!
I'm just a regular home user with a bunch of incoming snail (paper) mail. To get rid of the hassle to file the incoming stuff permanently I plan to scan it immediately and dispose afterwards.
I would prefer a document management system to just putting the scanned files in a folder. All DMS I found so far I rather enterprise grade (like Alfreso, Agorum Core).
EDIT:
Desired features would be:
- Tagging (hierarchical)
- Key - Value pairs attachted to the document
- Preview
- Indexing (of text documents)
Since I've never used a DMS before I'm not sure what is desriable.
How do you handle similiar situations?
System is KDE. Maybe there is a possibility to use the nepomuk tagging system...
Thanks!
Last edited by Osiris (2011-03-26 12:14:29)Desired features would be:
- Tagging (hierarchical)
- Key - Value pairs attachted to the document
- Preview
- Indexing (of text documents) -
Hi guys,
I wonder why, when I set the following instruction to detect the regional settings, I got different results using 1.3.1 vrs. 1.4.1?
String slRegion = System.getProperty("user.region");
If I use 1.3.1 then I got the right result, but if I use 1.4.1 I got a null value.
I need to use JDK 1.4.1, that's why I'm interested in getting the answer.
TIA.As I want to know the 2 letters of the countries, such as:
IN_USA = "US";
ES_MEXICO = "MX";
ES_ARGENTINA = "AR";
ES_BOLIVIA = "BO";
ES_CHILE = "CL";
ES_COLOMBIA = "CO";
ES_COSTARICA = "CR";
ES_REPDOMINIC = "DO";
ES_ECUADOR = "EC";
ES_SALVADOR = "SV";
What would it be the syntaxis (line code) to get this info?
I appreciate your help -
Ftp root and sharepoints setting bringing users right into home dir.
Hello, I pretty much understand the setup of ftp, but shouldn't the "ftp root and sharepoint" setting bring authenticated users into the ftp root first as the "/" directory? Then they should be able to access users since I have it shared and get into their directory if they need. But in my setup it brings them into their home directory first making it look just like the "home folders and sharepoints" setup. Any ideas?
This came up and bit me today, too.
If I set "Authenticated Users See:" to "Home Directory Only", it works as advertised and ftp users are dropped into their home directories.
If I set "Authenticated Users See:" to "FTP Root and Share Points", login invariably fails with the message "530 User username: can't change directory to /Users/username."
G5 Dual Mac OS X (10.4.8) -
Hi All !
i want to get currnet sytem directory in my code by
System.getProperty("user.dir");in my ide enviroment it is working properly but when i build executable .jar file
it returns active jre directory how can i get executable .jar file directory in my code when build it to .jar file?
thanksYes ...It is possible.
Just open the Server start Script (<DOMAIN_HOME>\bin\startWebLogic.cmd) and then set the following JAVA_OPTION There like :
<font color=maroon> In WINDOWS based OS (startWebLogic.cmd) Code Snippet</font><BR>
set DOMAIN_HOME=C:\bea103\user_projects\domains\base_domain
for %%i in ("%DOMAIN_HOME%") do set DOMAIN_HOME=%%~fsi
call "%DOMAIN_HOME%\bin\setDomainEnv.cmd" %*
set SAVE_JAVA_OPTIONS=%JAVA_OPTIONS% <b> -Duser.dir=E:/MyDirectory </b>
<font color=maroon> In UNIX based OS (startWebLogic.sh) Code Snippet</font><BR>
DOMAIN_HOME="/opt/app/bea103/user_projects/domains/base_domain"
. ${DOMAIN_HOME}/bin/setDomainEnv.sh $*
SAVE_JAVA_OPTIONS="${JAVA_OPTIONS}" <b> -Duser.dir=/opt/app/MyDirectory </b>
If you are starting your Servers from AdminConsole with the Help of NodeManagers then you can set the JAVA_OPTIONS like mentioned in the below Link:
http://jaysensharma.wordpress.com/2010/03/26/nodemanager-based-managedservers-setting-mem_args/
Maybe you are looking for
-
Is there a way to change the Windows Update service startup type on Windows Server 2012 R2?
We have a number of newly built 2012 R2 servers that we have HP Operations Manager agent running on that monitors the status of several services and reports if they are "stopped". One of these services is Windows Update. Every day we get at least one
-
Information about the ExternalConnection class inFramework.
There has been a lot of email asking about this class lately so here is the latest on the status of the ExternalConnection class. Currently the feature is in Beta. However it MAY be productized in 2F. After a successful period of beta testing for the
-
Weblogic Server 8.1 with Service Pack 6 will support for ALSB?
Hi, Can any body tell me, whether the ALSB is compatible with Weblogic Server 8.1? We have requirement to integrate ALDSP and ALESB using Weblogic Server 8.1. Thanks in advance. Regards, Ven
-
Solid State Drive For Macbook Pro mid 2012
Hi Apple Users, I would really appreciate some advice, a link would be great too. I am using a mid 2012 macbook pro with 16gb ram. After trouble here and there, slowing down here and there to the point I'm about to crack - solution = Solid State Driv
-
PipeLine Function Taking time to return Table record
Hi, I want to use a function in join clause. so i go for pipelined function(using for loop to get record & 1 more loop to fetch in table type variable). i achieved what i required. but problem is it takes much time to fetch data. is there any other a