How do i set the classpath in a unix environment using tsch script. I try to set the path as follows but it gives me errors
setenv CLASSPATH $CLASSPATH : path but it doens't work saying -Bad : modifier in $(/). i dont understand why i cannot set this class path. Due to this i cannot run my .jar executable as i want to and i am running out of time. When i try to run the .jar file it give s me the following error
new error...it shows this when i try to run the jar file along with the path to where my jar file is actually located and this is the error i receive
Error occurred during initialization of VM
java.lang.Error: Properties init: Could not determine current working directory.
at java.lang.System.initProperties(Native Method)
at java.lang.System.initializeSystemClass(System.java:1070)
It sounds like there are at least two issues here:
1) setenv CLASSPATH $CLASSPATH : path but it doens't work saying -Bad
: modifier in $(/).
This sounds like a "tsch" error calling "setenv" with a bad value for "$CLASSPATH". Take a look at your $CLASSPATH (or post it here): the problem should be apparent.
2) Error occurred during initialization of VM
This is because you don't have a classpath yet. But fixing your "setenv()" syntax might not necessarily fix the "java init" problem - we'll just have to take it one step at a time.
Please post the value of echo $CLASSPATH, the value before you try "setenv". That should help us fix problem 1)
The classpath should be set in the manifest file inside the jar. If not, you might try unpacking the jar and running it with the java -cp *myClassPath* *myMainClass* command.
You can set the classpath with environment variables - but why bother? If you run from a script anyways, I figure specifying the -cp option is much less error-prone.
Related
I am running Windows 10 and I recently ran into a problem with opening Eclipse. Originally, I was unable to use the javac command on command prompt because of a message that said: "javac is not recognized as internal or external program". To fix this, I went into the environment variables and added the PATH variable, which was not there before, and made the address to the bin folder in my Java folder. This fixed that problem and allowed me to use javac and run my files, however, now I am unable to open Eclipse. Whenever I run Eclipse, The program starts to load then fails and refers me to the log. In the error log I get this:
So far, I deleted that PATH variable then retried Eclipse and an error message said it was unable to find a javaw.exe file. I found my java files and put the path to that file in my eclipse folder and tried eclipse again. This time, eclipse started to load but then failed and referred me back to the error log. It seems that eclipse is able to find the javaw.exe file but I'm not sure what else is wrong now.
My Eclipse and Java versions were not compatible. IF anyone else has this problem make sure of that first. After fixing this, I went to the PATH environment variable and I was able to add multiple paths, so I added both of these:
C:\Program Files\Java\jdk1.8.0_161\bin
and
C:\Program Files\eclipse\jre\bin
The first path is necessary to use javac from command prompt. The second address is necessary for eclipse to access the javaw.exe file.
I've a java script who's running by several user and working very well.
Today, I asked another user to try the script on his desktop and he's getting a ClassNotFoundException... despite the script is perfectly the same as mine (and jar locations is also the same)
Here's the command tu launch the JAR :
java -cp .;customname.jar;libs/* my.package.MyMainClass
And I also tried to add every jar in the libs folder separately :
java -cp .;customname.jar;libs/lib.jar;libs/lib2.jar;libs/lib3.jar my.package.MyMainClass
And here's the error message the user is getting :
Error: Could not find or load main class ch.vaudoise.hp.services.listener.AutoSysReorder
I checked the JAVA configuration and try to set him the same java version on "Path" environment variable. Same error.
As there's 6 user who can run the script and only one who's getting an error I'm sure it's a configuration issue. But what ? Classpath seems to be OK...
Many thanks for any help..
First things first: You must start by finding where is the conflicting class. If you don't know it, you may find it in two alternative ways:
Programatically: Code this class and execute it with the same classpath (on an environment that does not suffer the problem):
public static void main(String[] args)
{
System.out.println(ch.vaudoise.hp.services.listener.AutoSysReorder.class. getResource("/ch/vaudoise/hp/services/listener/AutoSysReorder.class"));
}
Manually, one by one: Open a command shell and execute:
javap -cp . ch.vaudoise.hp.services.listener.AutoSysReorder
javap -cp customname.jar ch.vaudoise.hp.services.listener.AutoSysReorder
javap -cp libs/lib.jar ch.vaudoise.hp.services.listener.AutoSysReorder
javap -cp libs/lib2.jar ch.vaudoise.hp.services.listener.AutoSysReorder
...
Try one by one every entry in the classpath until the class is found.
Once found the location of the class, open a shell in the conflicting PC and make sure that path is accessible:
dir lib\conflicting-library-or-directory
Also, repeat the javap test:
javap -cp conflicting-library-or-directory ch.vaudoise.hp.services.listener.AutoSysReorder
After this tests, you should have more clues to find the cause of the problem.
Take a look at ClassNotFoundException despite class in the classpath
You are also including meta character (*) in your classpath.
Try without that as suggested in the link.
Also some times copy pasting to command line , may get some characters copied differently.
I cannot add comment as of now : So , editing this answer.
| Java path is not an issue.
Try the following step by step :
- find which jar the class that is being not found is in .
- include only that jar as cp.
- include only that class and try
java -jar that.jar
Also try this once
java -cp "*;"
If you still got issue , probably the jar does not contain the class (You can open jar and check).
And you say script - is this single command which is failing or is it part of script ?. Using java -jar -cp , usually ignores cp.
I am facing a very strange type of java classpath problem. I have added path d:\javaext in the java classpath environment variable and when enter on the command prompt echo %classpath% , it shows the said path in the printed list but even then, when I try to compile a java file in which I am importing the package by adding import org.apache.commons.lang.*;, it some how says that the said package doesn't exist. The relevant jar file physically exists on that path also. Any clue that what am I missing, although it's a very basic stuff. I have also tried compiling it with setting the classpath on runtime by javac -cp or javac -classpath switch but even then no success.
I am trying to compile the code with java 1.8 on windows 8.1
Can Anybody tell that what this alert means in the property dialog box of the jar file?
Your .Jar file might be corrupt.
Else on Windows try to set path through Environment Variable.
And on Linux , export the path for temporary usage or set in bashrc or bash profile.....
This could be caused by differences between version of a certain "jar", some third-party libraries does not support backward compatibility. So, try browsing through the "jar" to find the package-class combination that you are using.
Hope this helps,
Brian
Is it safe to assume that the are no spaces inside the path, e.g. "C:\Program Files"? If there are spaces, try surrounding the classpath variable with quotes.
I am having some trouble running a few jar's on a linux box. Basically, I am getting an error saying it cannot find the main class of my main jar. The class is defenetly present so it must be a classpath issue.
I am not great with linux, so I am looking for some advice as to where I might be missing something.
First off, I am setting the classpath in the users bash_profile; adding all the jar's required, seperated by a : delimeter. I then export the classpath.
Then, in the shell (ksh) script I use to invoke the main jar, I also st the classpath and call it in the command using -cp
so it looks like:
TEST_ROOTDIR = /Test/app
CLASSPATH=$CLASSPATH:${TEST_ROOTDIR}/lib/myjar.jar
...
export CLASSPATH
CMD_STRING="java -Xms200m -Xmx200m -XX:MaxPermSize=200m -verbose -cp $CLASSPATH"
CMD_STRING="$CMD_STRING <main classpath in jar>"
nohup $CMD_STRING > $OUTPUT_FILE
The output file shows all the jre jar's getting executed, it then loads the jar and throws a class not found exception for the main class.
I am stumped, any help would be greatly appreciated
The problem is in the following line:
TEST_ROOTDIR = /Test/app
I'm certain that upon executing the script, it'd have emitted an error message saying:
TEST_ROOTDIR: command not found
which you seem to have ignored. Remove the spaces around = while setting the environment variable. Say:
TEST_ROOTDIR=/Test/app
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.