I'm trying to setup a kiosk type system in linux where a java application launches when X is initialized. I've got a script which does the following:
java -cp {correct path to JAR with main method} -jar {name of JAR}
When I've cd'd into the directory where the JAR sits, everything is peaches and the system works like I want, however, if I navigate to any other directory, X terminates and reports that it could not access the JAR.
What am I missing here? Any help is greatly appreciated.
You don't need the -cp and the -jar
java -jar {full path}
should work. Your mainifest file in the .jar should then specify the appropriate main() method. See here for more details on that.
Related
My bash file is running fine in windows but it is not working in linux/mac.
I have created a selenium project with testng and I want to create a bash file so I can run my project without IDE
I have searched but till not getting any solution for same
Error on terminal:-
>bash TestNg_RunMe.bat
>Error: Could not find or load main class ..src.lib.selenium-java-2.46.0.jar
>TestNg_RunMe.bat: line 1: ./bin: Is a directory
Note:- I have use bash command also to run the command in linux and mac
Also lib and bin directory is present in right place(As it working fine in windows)
My bash file is :-
java -cp ./src/lib/*;./bin org.testng.TestNG testng.xml
Above bash is working perfect for windows
I have also tried with full absolute path
I have also extract testng.jar and add it in bash file
but nothing work.
Paths are separated using : under Unix-like systems and not ; as in Windows:
java -cp ./src/lib/*:./bin org.testng.TestNG testng.xml
If you are using bash under Windows then changing to : should work everywhere.
The ; character means end of statement to a Unix shell, so what you are attempting to exceute is:
java -cp ./src/lib/*
./bin org.testng.TestNG testng.xml
When I tried to do so with command java -jar samplewebdrivercode.jar then I found Manifest error.
Is it possible to do so?
Your file does not conform to the requirements of jar executable
Which should have an manifest file with Main-Class attribute if you want to run with -jar option.
Alternatively you can run the jar by specifying the class path with -cp or -classpath option, where the class should have an entry point i.e. main method.
The call can be done like this
java -classpath app.jar your.package.name.MainClass
I know about Groovysh, but I need to know if it is possible to run groovy CLI directly from groovy.jar placed in deployed war servlet (using one command). I can simplify question. Is there possibility to run Groovy CLI like it works, for example, in Clojure?
java -cp clojure-1.4.0.jar clojure.main
And CLI appears in terminal. This is how things look in clojure. I am looking for one line command which will run groovy CLI in terminal (using only groovy library to run it). I was looking for help in javadoc, found classes which should help, but don't know how to run it. :f
http://groovy.codehaus.org/api/groovy/lang/GroovyShell.html
(If someone knows solution which doesn't meet all criterias, also please answer.)
//EDIT
It seems that it needs groovy.jar, commons-cli.jar, antlr.jar, asm-util.jar and jline.jar. So I've added those files in my war file in WEB-INF/lib directory. Maybe it's good solution to make my own jar which role will be to call Groovy CLI from other jars, but now the question is, how ro run jar placed in WEB-INF/lib directory inside deployed war application via command line?
Greets
Seems like groovysh depends on more libs than the embeddable version contains. I managed to do what you want by using the following command:
$ java -classpath '*' org.codehaus.groovy.tools.shell.Main
But the current directory had to be the dir where all the groovy libs are; i.e. $GROOVY_HOME/lib:
$ cd $GROOVY_HOME/lib
$ java -classpath '*' org.codehaus.groovy.tools.shell.Main
Groovy Shell (2.0.6, JVM: 1.6.0_24)
Type 'help' or '\h' for help.
------------------------------------------------------------------------------
groovy:000>
I want to know how i can run a .jar file as a linux service. I am new to linux, so most of the online resources were not of much help.. Any input regarding this will be helpful..
It depends how you want to run jar. You can always run a java program as background task.
In bash
$nohup <path to java> -classpath <classpath> classname &
It looks like Java service wrapper is a solution that could fit your case.
The following that I have to use to run my groovy class file
..\bin\groovy.bat -cp ....;%classpath%;..\lib; GetTemplateNode.groovy
I am confused with .... part in the command before the groovy.bat and after the -cp.
Can you please explain me what each part of this command actually stand for?
Thank you
The .... is probably a mistake. Other than that, the command is starting the GetTemplateNode.groovy script, and adds the lib folder, that is located one folder above, to the classpath.