Avatar billede fredand Forsker
31. januar 2006 - 21:00 Der er 4 kommentarer og
1 løsning

is it possible to set -D params programaticaly?

Hello!

I found a couple of examples of JMS-code. Most of the apps is started with a -D parameter. Is it possible to set this inside of the code?

Exampele of -D param could look like:
java -Djava.naming.security.credentials=123qwe

Best regards
Fredrik
Avatar billede arne_v Ekspert
31. januar 2006 - 21:23 #1
Have you tried:

System.setProperty("java.naming.security.credentials", "123qwe");
Avatar billede arne_v Ekspert
31. januar 2006 - 21:24 #2
BTW, if this is your JMS question, then a file jndi.properties in classpath
with the properties you need should be fine (and more flexiable than hardcoding)
Avatar billede fredand Forsker
01. februar 2006 - 10:00 #3
Hello!

If I'm right I may set this in the Context like:

    java.util.Properties properties = loadProperties("jmslabb/jndi.properties");
    jndiContext = new InitialContext(properties);

    public static java.util.Properties loadProperties(String fileName)
    {
        try
        {
            java.util.Properties properties = new java.util.Properties();
            properties.load(new FileInputStream(fileName));
            return properties;
        }
        catch(Exception e)
        {
            e.printStackTrace();
            return null;
        }
    }
Where the jndi.propretis looks like:
java.naming.factory.initial=com.sun.jndi.ldap.LdapCtxFactory
java.naming.provider.url=ldap://xxx.xxx.xxx.com:7676/
java.naming.security.principal=admin
java.naming.security.credentials=xxxxxxxx
javax.jms.QueueConnectionFactory

An other way is to have the jndi.properties file in the classpath.

Best regards
Fredrik
Avatar billede fredand Forsker
01. februar 2006 - 10:02 #4
Hello Arne!
I just answered it my self!

Please give a svar so I can reward you!!

Best regards
Fredrik
Avatar billede arne_v Ekspert
01. februar 2006 - 17:02 #5
.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester