Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #166454 > unrolled thread

How do I set different JAVA_HOME for different users?

Started byJaimz Fairfax <captain_jtf@yahoo.co.uk>
First post2016-04-06 10:20 +0200
Last post2016-04-07 14:00 +0200
Articles 7 — 3 participants

Back to article view | Back to linux.debian.user

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  How do I set different JAVA_HOME for different users? Jaimz Fairfax <captain_jtf@yahoo.co.uk> - 2016-04-06 10:20 +0200
    Re: How do I set different JAVA_HOME for different users? "Thomas Schmitt" <scdbackup@gmx.net> - 2016-04-06 11:10 +0200
      Re: How do I set different JAVA_HOME for different users? SOLVED Jaimz Fairfax <captain_jtf@yahoo.co.uk> - 2016-04-06 16:10 +0200
        Re: How do I set different JAVA_HOME for different users? SOLVED Mark Fletcher <mark27q1@gmail.com> - 2016-04-06 16:20 +0200
        Re: How do I set different JAVA_HOME for different users? "Thomas Schmitt" <scdbackup@gmx.net> - 2016-04-06 18:00 +0200
          Re: How do I set different JAVA_HOME for different users? Jaimz Fairfax <captain_jtf@yahoo.co.uk> - 2016-04-07 12:50 +0200
            Re: How do I set different JAVA_HOME for different users? "Thomas Schmitt" <scdbackup@gmx.net> - 2016-04-07 14:00 +0200

#166454 — How do I set different JAVA_HOME for different users?

FromJaimz Fairfax <captain_jtf@yahoo.co.uk>
Date2016-04-06 10:20 +0200
SubjectHow do I set different JAVA_HOME for different users?
Message-ID<rkQQV-XV-3@gated-at.bofh.it>

[Multipart message — attachments visible in raw view] — view raw

I am running debian unstable, systemd version 229.I am learning Android development. 
Android Studio uses JAVA_HOME = /usr/java/jdk1.8.0_66.Some of the code I want to investigate uses Apache maven and that wants 
JAVA_HOME = /usr/lib/jvm/java-8-openjdk-amd64
I setup user2 so that when logging in JAVA_HOME is automatically set for maven.Except nothing I try will make it work.export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64" works in a terminal, but only for that terminal.
The internet thinks that /home/user2/.config/systemd/user.conf withDefaultEnvironment=JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64will work. It doesn't.
Thanks, Jaimz

[toc] | [next] | [standalone]


#166457

From"Thomas Schmitt" <scdbackup@gmx.net>
Date2016-04-06 11:10 +0200
Message-ID<rkRDk-1xY-19@gated-at.bofh.it>
In reply to#166454
Hi,

assuming you are running bash as shell, there are the startup files
for login and shell start.
>From man bash:

       /etc/profile
              The systemwide initialization file, executed for login shells
       /etc/bash.bashrc
              The systemwide per-interactive-shell startup file
       ~/.bash_profile
              The personal initialization file, executed for login shells
       ~/.bashrc
              The individual per-interactive-shell startup file

I have most of my personal preferences in ~/.bashrc .
Stuff like:

  export LC_COLLATE="C"
  export HISTCONTROL="ignoredups"
  export PS1='\u@\h:\W> '

So i guess it would be a good place to set

  export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"


Have a nice day :)

Thomas

[toc] | [prev] | [next] | [standalone]


#166464 — Re: How do I set different JAVA_HOME for different users? SOLVED

FromJaimz Fairfax <captain_jtf@yahoo.co.uk>
Date2016-04-06 16:10 +0200
SubjectRe: How do I set different JAVA_HOME for different users? SOLVED
Message-ID<rkWjE-52m-17@gated-at.bofh.it>
In reply to#166457

[Multipart message — attachments visible in raw view] — view raw

      From: Thomas Schmitt <scdbackup@gmx.net>
 To: debian-user@lists.debian.org 
 Sent: Wednesday, 6 April 2016, 9:59
 Subject: Re: How do I set different JAVA_HOME for different users?
  I have most of my personal preferences in ~/.bashrc .Stuff like:

  export LC_COLLATE="C"
  export HISTCONTROL="ignoredups"
  export PS1='\u@\h:\W> '

So i guess it would be a good place to set

  export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"
Have a nice day :)

Thomas

Thanks for that!
Adding 
 export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"to the end of ~/.bashrc fixed it.The internet seemed to be convinced that it had to be done via systemd user.conf.



  

[toc] | [prev] | [next] | [standalone]


#166469 — Re: How do I set different JAVA_HOME for different users? SOLVED

FromMark Fletcher <mark27q1@gmail.com>
Date2016-04-06 16:20 +0200
SubjectRe: How do I set different JAVA_HOME for different users? SOLVED
Message-ID<rkWtk-56i-33@gated-at.bofh.it>
In reply to#166464

[Multipart message — attachments visible in raw view] — view raw

On Wed, Apr 6, 2016 at 11:03 PM Jaimz Fairfax <captain_jtf@yahoo.co.uk>
wrote:

> The internet seemed to be convinced that it had to be done via systemd
> user.conf.
>
>
Unfortunately the Internet frequently talks bollocks, with great
confidence...

Mark

[toc] | [prev] | [next] | [standalone]


#166475

From"Thomas Schmitt" <scdbackup@gmx.net>
Date2016-04-06 18:00 +0200
Message-ID<rkY26-68Y-23@gated-at.bofh.it>
In reply to#166464
Hi,

Jaimz Fairfax wrote:
> The internet seemed to be convinced that it had to be done via systemd
> user.conf.

That opinion does not have to be wrong.
It depends on the level of software which you want to influence.
Environment variables are a very fundamental feature. Programs can
see them even if they have not been started by a shell. But of course,
the settings in the shell cannot influence what those programs see.
So it is sometimes necessary to use the init software or the desktop
to define the variable names and values for programs.

On the other side ot the spectrum, you may write wrapper programs
around the programs which you want to influence. Those wrappers
would set up the desired environment variables before starting the
desired program.
In the most simple case this would be a shell script like

  #!/bin/sh

  export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"

  android-emulator ...options...

So you can set up different environments per program rather than per
user.


Have a nice day :)

Thomas

[toc] | [prev] | [next] | [standalone]


#166497

FromJaimz Fairfax <captain_jtf@yahoo.co.uk>
Date2016-04-07 12:50 +0200
Message-ID<rlfFE-2v3-11@gated-at.bofh.it>
In reply to#166475

[Multipart message — attachments visible in raw view] — view raw

      From: Thomas Schmitt <scdbackup@gmx.net>
 To: debian-user@lists.debian.org 
 Sent: Wednesday, 6 April 2016, 16:50
 Subject: Re: How do I set different JAVA_HOME for different users?
   
Hi,

Jaimz Fairfax wrote:
> The internet seemed to be convinced that it had to be done via systemd
> user.conf.

That opinion does not have to be wrong.
It depends on the level of software which you want to influence.
Environment variables are a very fundamental feature. Programs can
see them even if they have not been started by a shell. But of course,
the settings in the shell cannot influence what those programs see.
So it is sometimes necessary to use the init software or the desktop
to define the variable names and values for programs.

On the other side ot the spectrum, you may write wrapper programs
around the programs which you want to influence. Those wrappers
would set up the desired environment variables before starting the
desired program.
In the most simple case this would be a shell script like

  #!/bin/sh

  export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"

  android-emulator ...options...

So you can set up different environments per program rather than per
user.


Have a nice day :)

Thomas

Thomas,A shell script exactly like that was what what I started out with!It worked ONLY for that terminal. 
I have seen a lot references to wrapper scripts but no examples for me to follow.I never thought to try 'man bash'.I did 'man environment' which returned nothing...The trouble is, often you need to know where to look, and if you know where to look you probably know the answer anyway.
Jaimz



  

[toc] | [prev] | [next] | [standalone]


#166498

From"Thomas Schmitt" <scdbackup@gmx.net>
Date2016-04-07 14:00 +0200
Message-ID<rlgLo-3f5-19@gated-at.bofh.it>
In reply to#166497
Hi,

> The trouble is, often you need to know where to look,

The collective brain here always has interesting proposals. :))


> A shell script exactly like that was what what I started out with!
> It worked ONLY for that terminal.

You'd need to put start of the whole android development into that
script. So that all processes started for that purpose inherit the
variable.


> I never thought to try 'man bash'.

It can be frustrating to search for answers in there.
Often you find the explanation why it works only after inventing a
way how it works.

In this case, bash is only involved as a common ancestor of all
your user's activity. When new processes get started, they normally
are subject to these statements from man 2 fork, when the parent process
duplicates itself:

  The
  new process, referred to as the child, is an  exact  duplicate  of  the
  calling  process,  referred  to as the parent, except for the following
  points: [... none of them applies to environment variables ...]

and man 3 execl, when the child process replaces the parent program by
the program which shall get started:

  For those forms not containing an envp pointer ( execl(), execv(), exe‐
  clp(),  and  execvp()), the environment for the new process image shall
  be taken from the external variable environ in the calling process.


Other ancestor programs (like systemd or the desktop) may of course
decide not to forward all their environment but construct a new set
of variables for those processes which they launch.


Have a nice day :)

Thomas

[toc] | [prev] | [standalone]


Back to top | Article view | linux.debian.user


csiph-web