Author Topic: Setting up java help  (Read 554 times)

shuiend

  • Member
  • **
  • Posts: 250
  • Kudos: 0
    • http://stuff4fools.topcities.com
Setting up java help
« on: 15 May 2003, 01:27 »
ok for skool i am startin to learn java. Our teacher says we have to use jcreater in windows. i say fuck that. I just installed the JDE and JRE on my red hat 9 box. Now how do i set my paths for users to there. I need to be able to use javac and such. the directory of where it istalled is /usr/java.
you know its a bad day when you look more sober then usual

Copperhead

  • Member
  • **
  • Posts: 39
  • Kudos: 0
Setting up java help
« Reply #1 on: 15 May 2003, 04:27 »
You need to add the bin directory of your Java installation to your PATH in /etc/profile. You separate your directories with a colon (    

#Example /etc/profile

PATH="/usr/bin:/usr/local/bin:/bin:/path/to/java/bin"

Write and quit that file, and then source it so you don't have to reboot.

$ source /etc/profile

That should do it. To test it do this:

$ java -version

It should return 1.4.1 or something along those lines.

Hope that helps.

[ May 14, 2003: Message edited by: Copperhead ]


shuiend

  • Member
  • **
  • Posts: 250
  • Kudos: 0
    • http://stuff4fools.topcities.com
Setting up java help
« Reply #2 on: 15 May 2003, 05:53 »
# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc

pathmunge () {
   if ! echo $PATH | /bin/egrep -q "(^| $1($| " ; then
      if [ "$2" = "after" ] ; then
         PATH=$PATH:$1
      else
         PATH=$1:$PATH
      fi
   fi
}

# Path manipulation
if [ `id -u` = 0 ]; then
   pathmunge /sbin
   pathmunge /usr/sbin
   pathmunge /usr/local/sbin
fi

pathmunge /usr/X11R6/bin after

unset pathmunge

# No core files by default
ulimit -S -c 0 > /dev/null 2>&1

USER="`id -un`"
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"

HOSTNAME=`/bin/hostname`
HISTSIZE=1000

if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
    INPUTRC=/etc/inputrc
fi

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC

for i in /etc/profile.d/*.sh ; do
    if [ -r "$i" ]; then
       . $i
    fi
done

unset i


thats my profile. Now where in that do i change it? i looked for the path book i am not sure how to put it in thwere
you know its a bad day when you look more sober then usual

Copperhead

  • Member
  • **
  • Posts: 39
  • Kudos: 0
Setting up java help
« Reply #3 on: 15 May 2003, 10:31 »
Put this line: "pathmunge /path/to/java/bin after" (without quotes) right before the line that reads: "pathmunge /usr/X11R6/bin after"

So, /etc/profile will look something like this:

#...stuff

pathmunge () {
if ! echo $PATH | /bin/egrep -q "(^| $1($| " ; then
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
fi
}

# Path manipulation
if [ `id -u` = 0 ]; then
pathmunge /sbin
pathmunge /usr/sbin
pathmunge /usr/local/sbin
fi

pathmunge /path/to/java/bin after
pathmunge /usr/X11R6/bin after

# stuff...........

I am not sure if you need to do this on Red Hat or not, but do this next:

$ source /etc/profile

That will make your new profile take effect with the added PATH entry, and save you from rebooting. Do this to test it out:

$ echo $PATH

You should see /usr/java/j2sdk1.4.1/bin or something like that.  Also, you can try:

$ java -version

which will return "Java SDK Version 1.4.1" or something like that.

You could also just edit the .bash_profile file in your /home/user directory. The PATH that is in there is only for THAT particular user. /etc/profile is system-wide, and thus probably a better option.

Just in case anyone cares, this "pathmunge" business is just a function to test to see if the root user is logged in (that is what the line "if [ `id -u` = 0 ];" is doing), and then by way of the pathmunge function, sets the Root User's PATH variable to the three paths it has listed (/sbin, /usr/sbin, /usr/local/sbin.) Apparently, there is some sort of security hazard with the .bash_profile file in the /root home directory, so Red Hat came up with this measure to replace .bash_profile with this pathmunge() function located in /etc/profile.

[ May 15, 2003: Message edited by: Copperhead ]


Calum

  • Global Moderator
  • Member
  • ***
  • Posts: 7,812
  • Kudos: 1000
    • Calum Carlyle's music
Setting up java help
« Reply #4 on: 15 May 2003, 13:45 »
is the pathmunge thing RH specific then? by that i mean it won't work with other systems, in particular i mean that i use slack, i don't have any pathmungeing going on in my /etc/profile (and users do not have a .bash_profile either, they all just get their settings from /etc/profile) and what i really mean is:
1) if i added a lot of pathmunge to my /etc/profile would it just not work because it's not red hat?
2) if i copied /etc/profile into /root as .bash_profile would i replicate the vulnerability, or is that red hat specific also? (what is this vulnerability anyway?)
visit these websites and make yourself happy forever:
It's my music! | My music on MySpace | Integrational Polytheism

shuiend

  • Member
  • **
  • Posts: 250
  • Kudos: 0
    • http://stuff4fools.topcities.com
Setting up java help
« Reply #5 on: 15 May 2003, 15:04 »
Thansk for that. I got it working. Just in time for skool to.
you know its a bad day when you look more sober then usual

Copperhead

  • Member
  • **
  • Posts: 39
  • Kudos: 0
Setting up java help
« Reply #6 on: 15 May 2003, 15:40 »
quote:
is the pathmunge thing RH specific then? by that i mean it won't work with other systems


No. Pathmunge() is just a function, defined in the /etc/profile file. When /bin/bash is executed, it first looks in the user's home directory (and this includes ROOT) for a .bash_profile file. If it doesn't find one there, it then goes into the system-wide applicable /etc/profile file to get its instructions.  From my experience, BASH is BASH. When you type in a command (let's use mplayer as an example ) BASH will first search the .bash_profile file for "mplayer" (it its PATHs), and if it can't find it in that PATH, or the .bash_profile doesn't exist, it checks the PATH in /etc/profile. It runs the same way no matter what distro it is installed on.

   
quote:
if i added a lot of pathmunge to my /etc/profile would it just not work because it's not red hat?


It will work. Out of curiosity, I tried it tonight on Debian Woody, and it works fine. I'll post my /etc/profile below with all of the comments with the modifications I made.


   
quote:
if i copied /etc/profile into /root as .bash_profile would i replicate the vulnerability, or is that red hat specific also? (what is this vulnerability anyway?)


Depending on what is in your /etc/profile, you would not want to copy its entire content's to /root/.bash_profile. Why you would want to do that is beyond me  :)  

As for the security vulnerability, I came across it when I was inquiring about pathmunge() on Red Hat's website for WJ / Bob. I flipped through a page that gave a run-down ofthe vulnerability, but since I don't run Red Hat, I really didn't pay much attention to it.  Now, I can't find the damned thing to save my life. LOL.

To sum it all up, I just think that this is another one of Red Hat's gimmicks of trying to be different.  It is simplified, in that pathmunge takes care of both Root's and User's PATHs all in one shot.   You can also structure the if/else ladded with the UID numbers (the if [ `id -u` = 0 ] part) to incorporate PATHs for users more efficiently. For example, if you are a SysAdmin at a programming company, and you have 200 people on your system, you first would assign a UID and then a GID to every person. If 100 of those people don't have write permission, even in their home directories (they would most likely have one folder in which they could compile their stuff), I guess this would save time from having to create 200 .bash_profile files in each user's directory. With this function, it allows you to assign PATHs to certain programs with either UID or GID, etc., and keeps it all in one place.  Or if you had a group of people working on C projets, and a group of people working on Java projects, you could distribute permissions and paths more easily with this pathmunge function.  

If you want to try it out, go for it. Just make sure you back-up /etc/profile before you get busy with it.

Here is my /etc/profile (with modifications and the pathmunge fucntion)

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

#PATH="/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games"
#JAVA_HOME="/usr/lib/j2se"
### The above two line I commented to test out pathmunge

pathmunge () {
if ! echo $PATH | /bin/egrep -q "(^| :)  $1($|i :) " ; then
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
fi
}

# Path manipulation
# if UID = Root
if [ `id -u` = 0 ]; then
#Set the superuser's PATH
pathmunge /sbin
pathmunge /usr/sbin
pathmunge /usr/local/sbin
fi

# Here you could get fancy, and set a normal user's path to whatever you wanted
# if [ `id -u` = 1000]; then
# Set the person with UID 1000, my normal account, in this case
# pathmunge /usr/local/bin
# pathmunge /copperhead/bin
# fi

# the path for ALL users
pathmunge /usr/X11R6/bin after
pathmunge /usr/games after

# unset the function so it doesn't execute continuously

unset pathmunge

# Basic default shell prompt configuration

if [ "$BASH" ]; then
  PS1='\u@\h:\w\$ '
else
  if [ "`id -u`" -eq 0 ]; then
    PS1='# '
  else
    PS1='$ '
  fi
fi

export PATH PS1
#export JAVA_HOME

# end /etc/profile

Hope that helps. Try it out  :)

[ May 15, 2003: Message edited by: Copperhead ]


Calum

  • Global Moderator
  • Member
  • ***
  • Posts: 7,812
  • Kudos: 1000
    • Calum Carlyle's music
Setting up java help
« Reply #7 on: 15 May 2003, 15:46 »
i never would have thought of that about defining different permissions for different uids, how clever.

i am still very new to scripting and almost everything about it goes over my head and i miss the clever little things that make life easy.
visit these websites and make yourself happy forever:
It's my music! | My music on MySpace | Integrational Polytheism

Copperhead

  • Member
  • **
  • Posts: 39
  • Kudos: 0
Setting up java help
« Reply #8 on: 15 May 2003, 16:03 »
Yeah, I love it too  

That is the beauty of Linux. You can take care of 200 things with a few lines of code (less than that if you are editing, and even less than that once you learn Perl). If you feel like using M$, your only option is to run the wizard 200 times, and watch your server choke on the lack of availible memory.

SAJChurchey

  • Member
  • **
  • Posts: 246
  • Kudos: 0
    • http://sajchurchey.htmlplanet.com
Setting up java help
« Reply #9 on: 16 May 2003, 07:19 »
you should really add similar lines to both /etc/profile and /etc/bashrc

Code: [Select]
SAJChurchey