WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Setting Path to Java JDK in /etc/profile in Microcore  (Read 11961 times)

Offline Terminator3000

  • Jr. Member
  • **
  • Posts: 64
Setting Path to Java JDK in /etc/profile in Microcore
« on: September 29, 2010, 03:57:39 PM »
Hi,having installed Java jdk1.6 (not openjdk extension) I'm trying to set the correct path but having no luck. I.ve placed it in /opt/java/jdk1.6.0_21/ and appended the path to the path line at the top of /etc/profile.
Ive added export path of JAVA_HOME also but its still not showing for an echo command.

Tips on setting up the correct path and actually getting it working welcome !


Offline danielibarnes

  • Hero Member
  • *****
  • Posts: 548
Re: Setting Path to Java JDK in /etc/profile in Microcore
« Reply #1 on: September 29, 2010, 04:12:50 PM »
It would help to elaborate on your modification to /etc/profile. I presume you added
export JAVA_HOME=/opt/java/jdk1.6.0_21
at the top?

It is not considered a good idea to modify /etc/profile directly. It is preferable to add a script (must end in .sh) in the /etc/profile.d/ directory that includes the necessary settings. This way, the settings can be added to your backup file or even an extension.

BTW, adding
PATH=$PATH:$JAVA_HOME/bin
is helpful also.

Offline Terminator3000

  • Jr. Member
  • **
  • Posts: 64
Re: Setting Path to Java JDK in /etc/profile in Microcore
« Reply #2 on: September 29, 2010, 04:40:04 PM »
Hi,having seen a few different methods it is dificult to know which one to use.
my full path is-:)   /opt/java/jdk1.6.0_21/bin/java      that is right up to the exe file.

The path at the top of /etc/profile is I presume just for the bash shell so I have un-appended the java path.
So still looking for the correct way to get the above java path recognised.


Offline danielibarnes

  • Hero Member
  • *****
  • Posts: 548
Re: Setting Path to Java JDK in /etc/profile in Microcore
« Reply #3 on: September 29, 2010, 05:06:52 PM »
Include the snippet from your /etc/profile (or attach the file if that is easier). I am not sure I understand what you changed.

My recommendation is to create the file /etc/profile.d/java.sh containing:

export JAVA_HOME=/opt/java/jdk1.6.0_21
export PATH=$PATH:$JAVA_HOME/bin

This should work as desired.

Offline maro

  • Hero Member
  • *****
  • Posts: 1228
Re: Setting Path to Java JDK in /etc/profile in Microcore
« Reply #4 on: September 29, 2010, 05:31:27 PM »
@Terminator3000: In my experience these kind of problems should be solved in two stages:
1. In a "standard" login shell test all the changes to variable settings until they work satisfactorily, e.g. adding the additional directory to $PATH (and not a target executable).
2. Make those admendment permanent by integrating them in an appropriate way.

I'm a bit hazy whether you had achieved the first target. Nevertheless I fully concur with what danielibarnes has meanwhile suggested. This should work based on the information you have otherwise provided.

Please note: The file name in '/etc/profile.d' has to conform to the "*.sh" naming convention (as suggested by danielibarnes). And don't forget to make an appropriate entry to '/opt/.filetool.lst', e.g. via echo 'etc/profile.d' >> /opt/.filetool.lst (which adds the whole directory and is therefore more future-proof). Finally don't forget to execute a backup, e.g. via  filetool.sh -b to include the change in your backup.

Offline Terminator3000

  • Jr. Member
  • **
  • Posts: 64
Re: Setting Path to Java JDK in /etc/profile in Microcore
« Reply #5 on: September 29, 2010, 06:06:06 PM »
I can clarify that I have installed the jdk1.6.0_21 program/directory in the /opt/java/ folder which I created and added to .filetool.lst. The path to this I listed in an earlier post and it is reliably constant.

I am just now trying to make a java.sh file with the code given to me above and hopefully the the path will resolve in an echo statement test. Many Thanks.

Offline Terminator3000

  • Jr. Member
  • **
  • Posts: 64
Re: Setting Path to Java JDK in /etc/profile in Microcore
« Reply #6 on: September 29, 2010, 06:26:40 PM »
To add to the above, I made a java.sh file in the /etc/profile.d/ directory with the above code,added to .filetool first and rebooted.
Whilst everything is in place still there is no resolve in terminal when I try echo $ JAVA_HOME it just returns
$ JAVA_HOME when it should be /opt/java/jdk1.6.0_21/bin.

So no joy yet for this simple task !

Offline maro

  • Hero Member
  • *****
  • Posts: 1228
Re: Setting Path to Java JDK in /etc/profile in Microcore
« Reply #7 on: September 29, 2010, 06:52:36 PM »
Did I detect there a blank character between the '$' and 'JAVA_HOME'? That clearly can't work, as the following example shows:
Code: [Select]
tc@box:~$ echo $ PWD
$ PWD
tc@box:~$ echo $PWD
/home/tc

Offline Terminator3000

  • Jr. Member
  • **
  • Posts: 64
Re: Setting Path to Java JDK in /etc/profile in Microcore
« Reply #8 on: September 29, 2010, 06:55:17 PM »
I also tried the same code in /etc/profile but it still didnt work.

code used was   export JAVA_HOME=/opt/java/jdk1.6.0_21
                          export PATH=$PATH:$JAVA_HOME/bin


Seems that getting exactly the right syntax is paramount.

Baffled, but it is probably something simple.

Offline Terminator3000

  • Jr. Member
  • **
  • Posts: 64
Re: Setting Path to Java JDK in /etc/profile in Microcore
« Reply #9 on: September 29, 2010, 06:57:34 PM »
Yes there was a blank character as I wasnt certain but I did try with no blank also,and that returns nothing at all.Thanks for pointing that out though now I know !

Offline Terminator3000

  • Jr. Member
  • **
  • Posts: 64
Re: Setting Path to Java JDK in /etc/profile in Microcore
« Reply #10 on: September 29, 2010, 07:15:16 PM »
So as I say its a little baffling,you would think it would be pretty straightforward but it doesnt seem to work.
Java installation is fine at /opt./java/jdk1.6.0_21/    but attempts to set path to it so far prove futile !

(Unless there is some way that java.sh script should be initialised on boot)

So for the moment I have a java.sh file in /etc/profile.d/ with the following code

export JAVA_HOME=/opt/java/jdk1.6.0_21
export PATH=$PATH:$JAVA_HOME/bin

Doesnt work !

More tips welcome !

« Last Edit: September 29, 2010, 07:35:12 PM by Terminator3000 »

Offline Terminator3000

  • Jr. Member
  • **
  • Posts: 64
Re: Setting Path to Java JDK in /etc/profile in Microcore
« Reply #11 on: September 29, 2010, 08:06:42 PM »
UPDATE ON ABOVE !!

Since rebooting (although I rebooted a few times before) it now seems that it is working.

That is,creating the java.sh file in the /etc/profile.d/ directory with the above posted lines of code written to it seems to do the job.

Now my 'echo $JAVA_HOME' command returns the path /opt/java/jdk1.6.0_21   so far so good !

Offline maro

  • Hero Member
  • *****
  • Posts: 1228
Re: Setting Path to Java JDK in /etc/profile in Microcore
« Reply #12 on: September 29, 2010, 08:10:54 PM »
All right, so far I get that your attempt to change '$PATH' has not worked as expected (the "empty response" indicates that the variable is not set.

I've now done a test using exactly these commands:
cat << EOF | sudo tee /etc/profile.d/java.sh > /dev/null
export JAVA_HOME=/opt/java/jdk1.6.0_21
export PATH=\$PATH:\$JAVA_HOME/bin

( date ; echo \$JAVA_HOME ; echo \$PATH ) >> /tmp/java_path.log
EOF

grep -q 'etc/profile.d' /opt/.filetool.lst \
    || echo 'etc/profile.d' >> /opt/.filetool.lst

filetool.sh -b


And the result is as expected: the $PATH has been changed to the desired new one after the next restart. Obviously the last line of the script (i.e. the one with the 'date' command) can be removed after it's working OK.

I got to admit that I had a bit of a laugh when reading:
Seems that getting exactly the right syntax is paramount.
In my experience in computing syntax is highly significant. It's not like cooking where it probably does not matter whether one uses 95g of sugar instead of 100g ...


EDIT: I only now saw the previous post about the success, I still leave this one standing for future reference. Or shall I call "educational" purpose?
« Last Edit: September 29, 2010, 08:15:38 PM by maro »

Offline Terminator3000

  • Jr. Member
  • **
  • Posts: 64
Re: Setting Path to Java JDK in /etc/profile in Microcore
« Reply #13 on: September 29, 2010, 08:37:39 PM »
Sorry for stating the blindingly obvious regarding the syntax,but I'm glad it tickled your funny bone !

I guess it was just frustration at not getting a simple task completed properly.

So  many thanks for your help but expect more problems from me as I quite like Microcore !

Cheers.