i'm very new to this world.. so forgive me for silly explanations.
I've installed maven and all the setting is done. Also i created a maven.sh
Content:
# Apache Maven Environment Variables
# MAVEN_HOME for Maven 1 - M2_HOME for Maven 2
export JAVA_HOME=/usr/lib/jvm/java-11
export M2_HOME=/opt/apache-maven
export MAVEN_HOME=/opt/apache-maven
export PATH=${M2_HOME}/bin:${PATH}
At this point everything is working as expected, but every time i close the terminal it seems to forget some settings..
I have to open the terminal and execute the following commands to make it work again:
~$ cd /etc/profile.d
~$ source maven.sh
I don't know if it is just the way to use maven or i'm missing something, but it's kind of annoying writting the same commands every single time i want to execute maven.. so i would appreciate if you can explain me a way to automate it.
Some extra information:
OS : Ubuntu 20.0.4
JDK : 11
Not first time creating JAVA_HOME variable
After executing those commands above, it shows the correct JAVA_HOME, but it's forgotten after closing the terminal and shows the wrong JAVA_HOME again
Let me tell you guys, this is my first question on stackoverflow, so i will understand if you want to correct me about my manners and my bad english (it's not my mother tongue, i have to get used to it)
Thank you in advance!
I can think of a couple of ways you could resolve this problem given your situation, which is not maven-specific but rather terminal-specific --
Add a reference to your maven.sh script to your profile so that it runs when you start a terminal session. This can typically be accomplished by creating (or adding to) the .bash_profile file in your home directory. You could either add the contents of your maven.sh script to that file, or add source /etc/profile.d/maven.sh to it. From that point forward when you start a terminal session, the script gets run automatically and your variables are set correctly. See https://joshstaiger.org/archives/2005/07/bash_profile_vs.html or the bash man page for some more details about the login shell
If you've already done the first step and it didn't work, consider checking to see if those environment variables are being set in another place (check ~/.bashrc, ~/.bash_profile, and anywhere your particular shell distribution / OS checks for startup scripts
Lastly, I recommend using SDKMan! to manage maven installs without these headaches -- but your mileage may vary. It handles keeping track of the environment variables, java version, &c and allows multiple Java/Maven versions to be installed and managed. https://sdkman.io
Sources:
https://joshstaiger.org/archives/2005/07/bash_profile_vs.html
https://linux.die.net/man/1/bash
https://sdkman.io
You can add these properties to individual user settings file. This file will be available in home directory
vi $HOME/.bash_profile
So everytime, you login to terminal, all these settings will be executed.
I solved the problem by doing a logout and login in Ubuntu
Related
I'm new to Stack Overflow (though a long time lurker).
I'm struggling to install elasticsearch on my laptop. It's windows 8, I've just updated java to Java 8 and I've set the new path using set JAVA_HOME.
However, whenever I try to run the elasticsearch.bat file on the command line, I get this error:
\elasticsearch-5.0.2\bin\..\config\jvm.options was unexpected at this time
Any help would be greatly appreciated on this matter
I've also tried to setup the ElasticSearch on my Windows 2016 R2 Datacenter (64-bit). Let me share some of my experiences on how to solve this.
Setting up JAVA_HOME
Ensure that you have JDK/JRE installed. You can download it here.
Set the JAVA_HOME environment variable. To do this, open the Start menu and type in "path".
Then click on Environment Variables. If you don't have JAVA_HOME variable set yet, click New.
The JAVA_HOME variable should only lead up to the JDK/JRE directory, not including /bin.
C:\Progra~1\Java\jdk1.8.0_112
Progra~1 corresponds to Program Files. If you use Program Files (x86), change Progra~1 to Progra~2
Restart your computer. Once your computer is restarted, open up CMD and type in echo %JAVA_HOME%. The output should be
C:\Progra~1\Java\jdk1.8.0_112
If you get the following output, your JAVA_HOME is setup correctly.
Running ElasticSearch
The first time I tried to run ElasticSearch, I get the following output.
The odd directory I pointed out here gave me a hint that the batch file might be reading from the wrong directory. So what I did was tinker around with the batch file a bit. Open elasticsearch.bat using any text editor.
Scroll all the way to the end, somewhere above the last lines you'll see something similar to the following.
Remove the highlighted line, save the file and try running the batch file again via command prompt.
It works in my case.
Once you have this, open up your browser and navigate to localhost:9200.
I think that's it?
Your problem is most likely caused by parentheses in the path to where you unzipped and are running Elasticsearch from. The related issue in the Elasticsearch repository is #24712 which will be fixed with Elasticsearch 5.4.1.
Be aware that by applying Nicholas Lie's "fix" you are telling Elasticsearch to effectively ignore all settings in config/jvm.options. While this may help you to start Elasticsearch in this specific case, it will only start with default JVM options which might lead to surprising behavior down the road.
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
I've used a number of different *nix-based systems of the years, and it seems like every flavor of Bash I use has a different algorithm for deciding which startup scripts to run. For the purposes of tasks like setting up environment variables and aliases and printing startup messages (e.g. MOTDs), which startup script is the appropriate place to do these?
What's the difference between putting things in .bashrc, .bash_profile, and .environment? I've also seen other files such as .login, .bash_login, and .profile; are these ever relevant? What are the differences in which ones get run when logging in physically, logging in remotely via ssh, and opening a new terminal window? Are there any significant differences across platforms (including Mac OS X (and its Terminal.app) and Cygwin Bash)?
The main difference with shell config files is that some are only read by "login" shells (eg. when you login from another host, or login at the text console of a local unix machine). these are the ones called, say, .login or .profile or .zlogin (depending on which shell you're using).
Then you have config files that are read by "interactive" shells (as in, ones connected to a terminal (or pseudo-terminal in the case of, say, a terminal emulator running under a windowing system). these are the ones with names like .bashrc, .tcshrc, .zshrc, etc.
bash complicates this in that .bashrc is only read by a shell that's both interactive and non-login, so you'll find most people end up telling their .bash_profile to also read .bashrc with something like
[[ -r ~/.bashrc ]] && . ~/.bashrc
Other shells behave differently - eg with zsh, .zshrc is always read for an interactive shell, whether it's a login one or not.
The manual page for bash explains the circumstances under which each file is read. Yes, behaviour is generally consistent between machines.
.profile is simply the login script filename originally used by /bin/sh. bash, being generally backwards-compatible with /bin/sh, will read .profile if one exists.
That's simple. It's explained in man bash:
/bin/bash
The bash executable
/etc/profile
The systemwide initialization file, executed for login shells
~/.bash_profile
The personal initialization file, executed for login shells
~/.bashrc
The individual per-interactive-shell startup file
~/.bash_logout
The individual login shell cleanup file, executed when a login shell exits
~/.inputrc
Individual readline initialization file
Login shells are the ones that are read one you login (so, they are not executed when merely starting up xterm, for example). There are other ways to login. For example using an X display manager. Those have other ways to read and export environment variables at login time.
Also read the INVOCATION chapter in the manual. It says "The following paragraphs describe how bash executes its startup files.", i think that's a spot-on :) It explains what an "interactive" shell is too.
Bash does not know about .environment. I suspect that's a file of your distribution, to set environment variables independent of the shell that you drive.
Classically, ~/.profile is used by Bourne Shell, and is probably supported by Bash as a legacy measure. Again, ~/.login and ~/.cshrc were used by C Shell - I'm not sure that Bash uses them at all.
The ~/.bash_profile would be used once, at login. The ~/.bashrc script is read every time a shell is started. This is analogous to /.cshrc for C Shell.
One consequence is that stuff in ~/.bashrc should be as lightweight (minimal) as possible to reduce the overhead when starting a non-login shell.
I believe the ~/.environment file is a compatibility file for Korn Shell.
I found information about .bashrc and .bash_profile here to sum it up:
.bash_profile is executed when you
login. Stuff you put in there might be
your PATH and other important
environment variables.
.bashrc is used for non login shells.
I'm not sure what that means. I know
that RedHat
executes it everytime you start
another shell (su to this user or
simply calling bash again) You might
want to put aliases in there but again
I am not sure what that means. I
simply ignore it myself.
.profile is the equivalent of
.bash_profile for the root. I think
the name is changed to let other
shells (csh, sh, tcsh) use it as well.
(you don't need one as a user)
There is also .bash_logout wich
executes at, yeah good guess...logout.
You might want to stop deamons or even
make a little housekeeping . You can
also add "clear" there if you want to
clear the screen when you log out.
Also there is a complete follow up on each of the configurations files here
These are probably even distro.-dependant, not all distros choose to have each configuraton with them and some have even more. But when they have the same name, they usualy include the same content.
According to Josh Staiger, Mac OS X's Terminal.app actually runs a login shell rather than a non-login shell by default for each new terminal window, calling .bash_profile instead of .bashrc.
He recommends:
Most of the time you don’t want to maintain two separate config files
for login and non-login shells — when you set a PATH, you want it to
apply to both. You can fix this by sourcing .bashrc from your
.bash_profile file, then putting PATH and common settings in .bashrc.
To do this, add the following lines to .bash_profile:
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
Now when you login to your
machine from a console .bashrc will be called.
A good place to look at is the man page of bash. Here's an online version. Look for "INVOCATION" section.
I have used Debian-family distros which appear to execute .profile, but not .bash_profile,
whereas RHEL derivatives execute .bash_profile before .profile.
It seems to be a mess when you have to set up environment variables to work in any Linux OS.
This question already has answers here:
Adding a directory to the PATH environment variable in Windows
(21 answers)
Closed 8 years ago.
I am having difficulties installing Maven.
I have set all the enviromental variables according to this: http://maven.apache.org/download.html
Although I am using windows 7, when I try and run the command mvn --version, I get, mvn is not recognized as an internal or external command etc.
When I run it from within src\bin, I get the error:
Exception in thread "main" java.lang.ClassNotFoundException: org.codehaus.plexus.classworlds.launcher.Launcher
at java.net.URLClassLoader$1.run<URLClassLoader.java:202>
at java.security.AccessController.doPrivleged(Native Method)
...etc
then:
Could not find the main class: org.codehaus.plexus.classworlds.launcher.Launcher.
Check that you don't have an M2_HOME environment variable.
I ended up on this question with the same problem, however, I had committed an elementary mistake of downloading the apache-maven-..*-src.zip instead of the apache-maven-..*-bin.zip
Once I realised that mistake, it was smooth sailing as soon as I corrected it. I suppose the instructions on the download page should be more than adequate
All you should need to do to install and use maven:
1) Download maven 3. The ZIP should be fine. Install it in a known place; I use c:\tools\ as the parent directory but your mileage may vary.
2) Set your PATH to point to the bin directory in the installation directory. If Maven is in c:\tools\maven-3.0.3 (as it is on my system), you'd add c:\tools\maven-3.0.3\bin to PATH:
set PATH=%PATH%;c:\tools\maven-3.0.3
You may also want to set MVN_HOME:
set MVN_HOME=c:\tools\maven-3.0.3
3) start a new command shell (cmd.exe). mvn should work; if not, you've skipped something here or something's badly wrong in your configuration.
blanking out M2_HOME worked for me on Ubuntu. Can test with just: 'export M2_HOME='
Your first problem is because you do not have maven in your PATH.
The second problem is what I had. I had both Maven 2 and 3 on my computer and even though I removed Maven 2 links from my PATH, it was still interfering with my new Maven.
You need to remove or rename the system variable M2_HOME.
1. Right click My Computer -> Properties
2. Advanced system settings
3. Environment Variables
4. Rename or delete M2_HOME
I setup M2_HOME like this:
export M2_HOME="~/app/apache-maven-3.1.1"
and saw the same exception:
Exception in thread "main" java.lang.ClassNotFoundException: org.codehaus.plexus.classworlds.launcher.Launcher`.
I changed to use absolute path and it worked:
export M2_HOME="Users/myaccount/app/apache-maven-3.1.1"
In my case, the M2_HOME env variable wasn't the problem. I think that java and/or mvn startup script doesn't expand the tilde in classpath cmd line args.
This is a question from long ago but recently i encountered this problem. In my case it was because i had M2_HOME set from a previous installation from months ago. I just unset the variable and after that was good to go.
I got the same error
In my case configuration which generate error
export M2_HOME="/home/ashoka/apache-maven-3.0.4/bin/"
PATH=$M2_HOME/bin:$PATH
Working configuration
export M2_HOME="/home/ashoka/apache-maven-3.0.4/"
PATH=$M2_HOME/bin:$PATH
Ashok Kumara
"mvn is not recognized as an internal or external command etc." means you haven't set your environment variable in windows. Read the whole http://maven.apache.org/download.html :-)
Do you have maven 2 also installed?
I found one link in searching, see if it helps
http://blogs.oracle.com/sreekanth/entry/java_lang_noclassdeffounderror_org_codehaus
and also double check your environment variables to make sure you have set all the variables mentioned in the doc.
For this error "mvn is not recognized as an internal or external command", add src/bin folder in 'path' environment variable.
Like Joseph Ottinger said, you have to put Maven installation directory to your PATH environment variables or User variables. You can edit user variables by running command "rundll32 sysdm.cpl,EditEnvironmentVariables" without quotes.
First add new variable called MAVEN_HOME and for it's value Mavens installation directory ie. c:\tools\maven-3.0.3\ then edit PATH variable and add end of the value ;%MAVEN_HOME%\bin (notice semicolon)
After re-login or opening new command prompt mvn command should work perfectly.
Some people seem to have trouble with adding Maven bin folders to the System PATH vs the User PATH. You could try defining your environment under your User variables, but this would be more of a workaround than a solution.
PATH=%PATH%;%JAVA_HOME%\bin;%JRE_HOME%\bin;%MAVEN_HOME%\bin
You can diagnose these access errors with Rapid Environment Editor, which will tell you if certain PATH locations are invalid or inaccessible to you.
I do most of my work against JDK 1.5 - but occasionally I have to change to 1.6. it is a bit painful to have to manually go and change my 'JAVA_HOME' system variable whenever I need to work on a project specific to one or the other (and no, Eclipse doesn't play well in these scenarios - trust me...I've tried.)
I'm looking for a registry script or windows shell script or for that matter any means by which I can "toggle" this system variable with something that is easy to run.
I've messed with the 'set' command, but that only sets the variable for that particular command instance - not globally.
Thanks in advance.
EDIT #1:
Points of advise:
Use the JAVA_HOME variable in your path variable as well, that way you only have to change the JAVA_HOME (which is used in many projects anyways [maven, ant, etc])
Write the command into a couple batch scripts for easy use
When you make the change the windows command session will not reflect it right away. You must close and reopen it.
You could use setx for that purpose
Like so:
setx /M JAVA_HOME "C:\Program Files (x86)\Java\jdk1.6.0_17"
I'm trying to get my Apache Lucene demo to work and I'm down to setting the classpath in this tutorial http://lucene.apache.org/java/2_3_2/demo.html
I've hunted the web and these wer the 2 solutions I found to set CLASSPATH:
CLASSPATH=${CLASSPATH}:/Users/philhunter/Desktop/COM562\ Project/lucene-3.0.3/lucene-core-3.0.3.jar
and
setenv CLASSPATH ${CLASSPATH}:/Users/philhunter/Desktop/COM562\ Project/lucene-3.0.3/lucene-core-3.0.3.jar
The second one brings up a error
-bash: setenv: command not found
The first one seemed to accept ok but wen i tried the next step in the tutorial i got an error. The next step was to run the following:
Phil-hunters-MacBook:webapps philhunter$ java org.apache.lucene.demo.IndexFiles /Users/philhunter/Desktop/COM562\ Project/lucene-3.0.3/src
which gave me the error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/lucene/demo/IndexFiles
This leads me to believe my CLASSPATHS didnt set correctly. Would I be right in assuming this? I have tried other tutorials and demos and see to get this same error quite a bit. Im new to Lucene and relatively new to mac and Unix shell scripting. Anyone know if I am setting the CLASSPATH correctly and if thats the cause of the errors?
in the terminal type
$ vim ~/.bash_profile
edit the file and add one line:
export CLASSPATH=${CLASSPATH}:/usr/local/lucene-3.6.2/lucene-core-3.6.2.jar:/usr/local/lucene-3.6.2/contrib/demo/lucene-demo-3.6.2.jar;
make sure to change the path of yours.
In your way you lose to add lucene-demo-3.0.3.jar in your classpath.
When you set an environment variable like CLASSPATH then by default it only applies to the current process (i.e. the shell process itself) - it isn't available to the java process you launch in the next line. In order to make it available to other processes you need to "export" the variable. In this case you can use something like:
export CLASSPATH=${CLASSPATH}:/Users/philhunter/Desktop/COM562\ Project/lucene-3.0.3/lucene-core-3.0.3.jar
This basically says "set the CLASSPATH variable to its current value plus the location of the lucene jar, and make the new variable available to any processes launched from this shell".
However, with java the usual way of setting the classpath is to do it as part of the java command itself, using the -classpath or -cp options. In your case it would look something like:
Phil-hunters-MacBook:webapps philhunter$ java -cp /Users/philhunter/Desktop/COM562\ Project/lucene-3.0.3/lucene-core-3.0.3.jar org.apache.lucene.demo.IndexFiles /Users/philhunter/Desktop/COM562\ Project/lucene-3.0.3/src
As an aside, the error you see when using the setenv line is because setenv is the command used in the C shell to set environment variables, but the default Mac shell (and the shell you're using) is bash which doesn't recognise setenv and lets you know it doesn't recognise it with the error message: -bash: setenv: command not found.
i create a .bash_profile file in my home directory and do things like
export GRAILS_HOME=/usr/share/grails
...
export PATH=${GRAILS_HOME}/bin:${GROOVY_HOME}/bin:/usr/local/mysql-5.1.45-osx10.6-x86_64/bin:${PATH}
you can work of that to set the classpath -- these examples show how to declare an environment variable and how to use the variable in other variables.