setting classpath using setenv.sh for a project - java

I want to write an sh file that will set classpath in Linux.
I tried using:
export ClASSPATH=$CLASSPATH:$ABC_HOME
However, when I run the .sh file it doesn't set the classpath.

Executing the bash script only sets the environment for the child process. The "source" command may do what you want...
https://askubuntu.com/questions/53177/bash-script-to-set-environment-variables-not-working

You should make it a shell function, or source it. Because the environment variables are local to the shell (the one started by invoking your shell script).
Please read the advanced bash scripting guide. See also this answer to a similar question.

Related

How to run JMeter through CMD from jdk/bin directory?

I want to run JMeter test plans from a UNIX server where env variables for java is not set. Its a test server and I dont have access to set that. We have different JDK versions and all are sitting in directories. I need to run my JMeter TestPlans on this server. I went to JDK /bin folder and tired to execute the below command
$ {jmeter-path}/bin/jmeter -nt testplan.jmx -l testresult.jtl
but this says
./bin/java: not found
But if I do simple java -version it shows the version result.Is that something that JMeter needs specifically the java env variable set or it wont run ? I dont have permission to set and I want to run the testplan using the JDK/JRE from its directories. A help would be appreciated. Thanks in advance!
UPDATE:
I think I could work around this by editing the jmeter script file as suggested in the one of the comments. Since my requirement was running the JMeter from a specific server, I could achieve this by editing the JAVA_HOME variable value in the script.
JMeter looks for java executable in system PATH so you have 2 options:
Add bin folder of your JDK or JRE to PATH, something like:
PATH=$PATH:/location/of/your/jbk/bin && export PATH && {jmeter-path}/bin/jmeter -nt testplan.jmx -l testresult.jtl
Or if you have java in PATH just run ApacheJMeter.jar like:
java -jar {jmeter-path}/bin/ApacheJMeter.jar
You might also want to use jmeter.sh wrapper script instead of jmeter, it has some logic regarding java binary location
More information: Get Started With JMeter: Installation & Tests
The official JMeter Getting Started documentation says this:
To install a release build, simply unzip the zip/tar file into the directory where you want JMeter to be installed. Provided that you have a JRE/JDK correctly installed and the JAVA_HOME environment variable set, there is nothing more for you to do.
Based on the symptoms that you reported, I think that you have not set JAVA_HOME correctly. It should be set to an absolute path to your Java installation's top directory.

'JAVA_HOME is not set' error while installing pig. What to do about it?

I followed all the steps on pig.apache.org ,but not able to remove this error by setting java variable. I set the variable earlier while installing java jdk but its asking again for the variable.
You need to understand how environment variables work in Linux (or Windows).
The chances are that you only set JAVA_HOME temporarily in the shell that you used to do the installation. To set JAVA_HOME permanently (on Linux / UNIX) you need to set it in a shell "rc" file that gets run each time a new shell is created. (It depends on which shell you are using, but man can tell you about that ...)
if you are installing PIG on ubuntu do this
open bashrc file using below command and and lines to the end of the file
vi ~/.bashrc
export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-i386
then log out or Restart your system and try again.
For CentOS
Create a new file called java.sh
vim /etc/profile.d/java.sh
Within this file, initialize the necessary environment variables
export JRE_HOME=/usr/java/jdk1.5.0_12/jre
export PATH=$PATH:$JRE_HOME/bin
export JAVA_HOME=/usr/java/jdk1.5.0_12
export JAVA_PATH=$JAVA_HOME
export PATH=$PATH:$JAVA_HOME/bin
Replace java path with your java installation.
Source
To set your JAVA_HOME variable for your current shell, use the export command. This will immediately create an environment variable for JAVA_HOME, but the variable is lost when your shell is closed.
export JAVA_HOME=<path_to_java_sdk>
The best way to set the JAVA_HOME environment variable for Pig and Hadoop use is by adding it to your local rc file. The reason for this is that some distributions of Hadoop (Cloudera, Hortonworks, MapR) may include their own Java installation for the Hadoop application itself. You may not want to create a global environment variable, since it may interfere with Hadoop/Hive/etc.
To have the variable set for individual Hadoop/Pig users on the server, they need to run the following command:
echo "export JAVA_HOME=<path_to_java_sdk>" >> ~/.bashrc
Afterward executing the command, they can source ~/.bashrc to instantiate the environment variable.

What does -cp mean in the terminal when running a .jar file?

I have to get some kinks out of a shell script for work, and one of the line looks like this:
-cp: this is the classpath
This is the set of classes that are used when running a specific class.
In your example; OrganT.Tune.Mix OrganT must be a class in the classpath (in this case, inside the OrganT.jar
Read the documentation, can be found here
Just a hint - under linux and mac you can use the
man <command goes here>
comman in the terminal/shell to display all parameters and usage information available for the specific command.
-cp stands for classpath. The CLASSPATH variable is one way to tell applications, including the JDK tools, where to look for user classes.
java -classpath .;YourJarFile.jar
I think you want to run a script for including the class path and execute the jar.
To do this in any text editor type java -jar YourJarFile.jar and save it, with extention (anyName.sh) assuming you have got linux flavour. Make it executable using the command chmod 775 anyName.sh
For windows type java -jar YourJarFile.jar, and save it with extention (anyName.bat)

How to set java environment variable on mac

How do I set a java environment variable that can be read with System.getenv() on Mac OS X Lion? I developing in Eclipse.
I used this command in the terminal export VAR_NAME=Value but System.getEnv(VAR_NAME) returns null.
I tried java -DVAR_NAME=Value but nothing is executed. I only get the java arguments help.
I created in my current project folder the file .bash_profile with the content: export VAR_NAME=Value. It's not working.
I also created the folder .MacOSX with a single file inside environment.plist and in this file I wrote the property and its value using XCode. Nothing is working.
How do I do it?
It is not clear what you are actually doing here. If you are trying to set an environment variable for a Java command you are launching from Eclipse, then the simple solution is to set it via the Eclipse command launcher configuration. Another alternative is to:
exit Eclipse,
run export VAR_NAME=Value in a command shell instance, and
launch Eclipse from that same shell instance.
Re the things you tried.
I used this command in the terminal export VAR_NAME=Value but System.getEnv(VAR_NAME) returns null.
If you run the export command from a command prompt, and then immediately launch the command from the same command prompt, that should work. The export command is telling the shell instance used by the command prompt to add VAR_NAME to this list of environment variables it exports to child processes that started after running the export command. Child processes that have all ready been started won't see the changes.
I strongly suspect that you ran the export after you launched Eclipse ... or that you didn't start Eclipse from that shell instance. If either of those two is true, the export command wouldn't affect Eclipse's environment variables which it (by default) passes on to any Java program you launch from Eclipse.
I tried java -DVAR_NAME=Value but nothing is executed. I only get the java arguments help.
That fails for a couple of reasons:
the -DVAR_NAME=... is setting a system property not an environment variable, and
you haven't told java the name of the class that you want to start!
I created in my current project folder the file .bash_profile with the content: export VAR_NAME=Value
That only affects new shell instances that are launched after you created the file. It doesn't affect the existing one.
I also created the folder .MacOSX with a single file inside environment.plist and in this file I wrote the property and its value using XCode.
I've no idea what that would do. Where did you create that folder?
1.open the Terminal
2.export VAR_NAME=Value
3.open /Applications/Eclipse.app

How to Run a Simple Java Program

I dad left Java since so long as a result now it happens that sometimes I forget the simple things and used to behave like a Stupid.
To run a Simple Java program say "Hello World" written in Notepad what do I have to Do?
I know the commands javac "Filename.java" and java "Filename" respectively to run it from the Command prompt.
But When I try to do that I got this message:
"javac is not recognized as an internal or external command, operable program or batch file."
and I could not Complie the file.
I hava little idea that we need to do some stuffs like setting the classpath or perhaps the path evnironment variables but it was exactly that I don't remember.
Can anybody please help me?
Thanks,
david
Add a JAVA_HOME env variable to point to the jdk installation directory
To your PATH env variable, add %JAVA_HOME%\bin
Add a CLASSPATH env variable to point to %JAVA_HOME%\lib.
remember to open a new console window and try running javac and java - everything should be fine now.
1) create JAVA_HOME environmental variable set value to java home directory
e.g. c:\program files\java\jdk1.5;
1) set PATH in environmental variable to your java bin directory
e.g. %JAVA_HOME%\bin
and to check classpath is set correctly run javac command on cmd
and this link will help to create and run simple java application
java tutorial
this might be usefull budddy
http://www.apl.jhu.edu/~hall/java/beginner/settingup.html
You need the JDK to be able to run javac.
I suggest you first start coding in eclipse, it provides all the environment set up for you. Once you get good with coding, you can try command prompt compiling and running. That way, you will be confident with language first and then go into the nitty-gritties of the environment and set up.
Its better to use any java IDE either eclipse or netBeans Download Link
But in case if you like to go through Command prompt method, then u need to set the paths. (These are the variables for your OS, that used to know where your commands e.g. java or javac etc are located). Hope from other answers you set the paths.
Good luck

Categories