jar path on unix

Hi

I was giving propertie file path in java class like this

public static final String APPLICATION_PROPERTY_FILE_PATH ="\\\\machinename.com +

"\\workspace\\Agr\\JavaSource";

Now issue is this I deployed this as jar file on linux like b.jar.

Now it is complaining that Unable to locate resource application.properties obviously becuase of window path.

now what path i should give for unix

my jar is in home/ras/jar/b.jar/application.properties

regards

[506 byte] By [smita_smitaa] at [2007-10-3 7:43:57]
# 1
Paths containing (single) forward slashes are reasonably portable between filesystems. However, the specifics of how to refer across the nework to a resource is platform specific.
dcmintera at 2007-7-15 2:45:07 > top of Java-index,Java Essentials,Java Programming...
# 2
jar is is installed on unix only
smita_smitaa at 2007-7-15 2:45:07 > top of Java-index,Java Essentials,Java Programming...
# 3
What's your point?
dcmintera at 2007-7-15 2:45:07 > top of Java-index,Java Essentials,Java Programming...
# 4

Hi

i repeat

build has develped on windows so i gave application property path as

public static final String APPLICATION_PROPERTY_FILE_PATH ="\\\\machinename.com +

"\\workspace\\Agr\\JavaSource";

now same build is going to deploy on unix in JAR FORMAT.

i deployed this jar file as b.jar

Now it is complaining that Unable to locate resource application.properties obviously becuase of window path.so i need to change that above path to unix path

so i tried

public static final String APPLICATION_PROPERTY_FILE_PATH ="\\\\scx.x-.dhl.com\\home\\wasadmin\\jar\b.jar";

but still getting same error unable to locate application properties

may be becuase file is inside jar format?

regards

smita_smitaa at 2007-7-15 2:45:07 > top of Java-index,Java Essentials,Java Programming...
# 5

And as I pointed out, the machine part of that path is going to be platform dependent. Within the filesystem you can use forward slashes. If the machine in question is mounted on the local filesystem you'll be able to simply include the path to that.

Without appropriate configuration, it will not be possible to access a remote machine using a filesystem path. The specifics of that configuration are up to you, so I cannot determine them in advance.

If you are not accessing a remote machine, simply omit the machine name from the path.

dcmintera at 2007-7-15 2:45:07 > top of Java-index,Java Essentials,Java Programming...
# 6
ok i try by removing machie namemy worry is that the application.properties inside the jar deployed on machine so whethere it will take file inside jar or not
smita_smitaa at 2007-7-15 2:45:07 > top of Java-index,Java Essentials,Java Programming...
# 7
Properties files are normally read from the locations defined in the classpath.
dcmintera at 2007-7-15 2:45:07 > top of Java-index,Java Essentials,Java Programming...
# 8

mine is taking from java file so i have to do like that only

i changed to this

public static final String APPLICATION_PROPERTY_FILE_PATH ="\\home\\wasadmin\\jar"

where jar folder contains application.properties but error is same

one more doubt have on unix it is / but I am using \

smita_smitaa at 2007-7-15 2:45:07 > top of Java-index,Java Essentials,Java Programming...
# 9

> mine is taking from java file so i have to do like

> that only

Is this your application? If so, why have you hard coded the path to your property file? That's incredibly poor practice for precisely this sort of reason. Fix it to load it from either the classpath or the working directory. Or specify it as a command line parameter.

> one more doubt have on unix it is / but I am using \

This: / is a forward slash. This: \ is a back slash. Java will always accept forward slashes. You don't need to double forward slashes up as / is not an escape character.

dcmintera at 2007-7-15 2:45:07 > top of Java-index,Java Essentials,Java Programming...
# 10

no not mine I am just deploying on unix.

due to application requirement claspath can not be used

this is in constants.java

public static final String FILE_SEPARATOR = System.getProperty("file.separator");

public static final String APPLICATION_PROPERTY_FILE = "application.properties";

public static final String APPLICATION_PROPERTY_FILE_PATH ="\\home\\wasadmin\\jar";

and this loading that properties file

applicationProperties = PropertiesReader.loadProperties(

Constants.APPLICATION_PROPERTY_FILE,

Constants.APPLICATION_PROPERTY_FILE_PATH);

smita_smitaa at 2007-7-15 2:45:07 > top of Java-index,Java Essentials,Java Programming...
# 11
any idea I need it urgently
smita_smitaa at 2007-7-15 2:45:07 > top of Java-index,Java Essentials,Java Programming...
# 12

> no not mine I am just deploying on unix.

> due to application requirement claspath can not be

> used

Hardcoding a path is stupid. If your requirements say you can't take either of the other options I suggested then your requirements are dumb and should be changed.

I'm curious as to what you're doing as it's not anything compatible with the way I'd normally use WAS. I strongly suspect that you're doing something wrong.

Please elaborate on what you're trying to achieve at a higher level than path issues.

dcmintera at 2007-7-15 2:45:07 > top of Java-index,Java Essentials,Java Programming...
# 13
> any idea I need it urgentlyTough. I'm off to bed.
dcmintera at 2007-7-15 2:45:07 > top of Java-index,Java Essentials,Java Programming...
# 14

anyhow that has been done by other guy but while installing on linux I am getting error

folowing are the three files constants.java

1)public class Constants

{

public static final String FILE_SEPARATOR = System.getProperty("file.separator");

public static final String APPLICATION_PROPERTY_FILE = "application.properties";

public static final String APPLICATION_PROPERTY_FILE_PATH ="path for unix need to berefor widows they have mentioned \\\\machine name\\folder";

properties file is present in /home/wasadmin/jaron linux machine

2)propertiesreader.java

public abstract class PropertiesReader

{

protected PropertiesReader()

{

super();

}

public static Properties loadProperties(String propertiesFile, String propertiesFilePath)

throws IOException

{

if(propertiesFile == null || propertiesFile == "")

throw new IOException("Properties file name is empty or null");

if(propertiesFilePath == null || propertiesFilePath == "")

//throw new IOException("Properties file path is empty or null");

throw new IllegalArgumentException(propertiesFilePath);

Properties properties = new Properties();

InputStream in = null;

System.out.println("hi");

String fileSeparator = System.getProperty("file.separator");

try

{System.out.println("hi");

in = new FileInputStream(

new File(propertiesFilePath+fileSeparator+propertiesFile));

System.out.println("bhi");

properties.load(in);

} catch (FileNotFoundException e)

{

throw new IOException("Unable to locate resource "+ propertiesFile);

}

finally

{

if(in != null)

{

in.close();

}

}

return properties;

}

}

3)in this code file is loaded

public static void main(String[] args)

{

Properties applicationProperties = null;

PropertiesUtil propertiesUtil = null;

Properties queryProperties = null;

PropertiesUtil queriesUtil = null;

try

{

Logger logger = Logger.getLogger(AuditDataHandler.class);

//System.out.println(Constants.APPLICATION_PROPERTY_FILE_PATH);

applicationProperties = PropertiesReader.loadProperties(

Constants.APPLICATION_PROPERTY_FILE,

Constants.APPLICATION_PROPERTY_FILE_PATH);

smita_smitaa at 2007-7-15 2:45:07 > top of Java-index,Java Essentials,Java Programming...
# 15
after loading in third file there is one more linepropertiesUtil = new PropertiesUtil(applicationProperties);
smita_smitaa at 2007-7-21 12:06:38 > top of Java-index,Java Essentials,Java Programming...