Unable to understand relative path in Groovy.bat -cp command - groovy

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.

Related

Where is the "program" module that some bash scripts require before launching Node.JS?

I found a Bash script today that uses the env command to launch Node.JS. The script requires two packages and then uses the second package to parse the process command line arguments before launching node as shown below:
#! /usr/bin/env node
'use strict';
require('zos-lib').Logger.silent(false);
require('./program').parse(process.argv);
I can't find a module/package named './program' anywhere in my file system. Can someone tell me where the program module/package is and what it does? I tried many Google searches but unfortunately program is such a common keyword that I'm not finding anything useful.
UPDATE: slebetman's answer is correct. I wanted to explain why I couldn't find the program module in this update, in case it helps others. As soon as I read his answer about that script being a Javascript script and to look for program.js not program I found it by searching the directory tree from the top level Node.js directory with this command:
$ find . -iname program.js
Unfortunately for me, what you see below is what I tried the first time and that does not produce any output:
$ find . -iname program
The script you found is not a bash script. It is a javascript script. Specifically it is a script written in javascript for node.js.
In node's require system, a module name that begins with ./ means that the module is in the same folder as the script.
You haven't told us the file name of the script you posted. But lets assume it's called myscript.js. Then the folder structure should be:
/whatever/folder/myscript.js
/whatever/folder/program.js
or
/whatever/folder/myscript.js
/whatever/folder/program/index.js
or
/whatever/folder/myscript.js
/whatever/folder/program/package.json
/whatever/folder/program/whatever_script_name.js
If you cannot find the file program.js or the folder program in the same folder as the script you are looking at then you haven't copied the script properly (you forgot to copy the "program" file or folder).

run Groovy CLI from groovy jar placed in war

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>

How to run a Scala program via cron?

I wrote a small Scala application. I have 2 classes in one source file including the App trait runner to start the program. It works just fine when I run it in the terminal:
scalac update.scala // compiling
scala update // run it
Now I want to run it with a cron job. For this I edited sudo crontab -e and added this:
*/2 * * * * scala /usr/bin/local/update
and made the script executable but nothing happend so far. I'm not sure how to do it:
Do I have to make a jar file for this?
Do I have to add this before my classes or not?
#!/bin/sh
exec scala -savecompiled $0 $#
!#
Does anyone have some experience with this?
Thanks in advance.
I suspect scala isn't in $PATH where cron can see it.
Try the following in a shell session:
$ which scala
Which should output something like "/opt/scala/2.9.1/bin/scala" or something. Could be in /usr/local, any number of places - java and the unix filesystem don't really play together nicely.
So now you have two options:
Put the folder where scala lives in the system path (This will usually involve editing /etc/profile, but you don't specify the OS so I can't say for sure)
(Easier) Just change the the cron entry to call /full/path/to/scala rather than just "scala"
The scala command expects the name of a compiled runnable object or a file containing a scala script source (or a runnable jar file) as the thing to run.
If you have in update.scala object update extends App (and no package declaration) then after scalac update.scala (which should have produced a bunch of *.class files) scala update is the right thing to run.
If the produced class files are not in the current directory then the -classpath option should be used to tell scala where to find them, as in eg. scala -classpath /usr/bin/local update, if the class files are indeed in /usr/bin/local.
Saying scala /usr/bin/local/update would make sense if the file /usr/bin/local/update (this exact name) contained scala script source (that is more or less a sequence of scala expressions not wrapped in a class or object).

Ant build in linux

I'm trying to run an ant build in linux and I'm getting odd results. I can't seem to get anything to run without specifying each and every library on the classpath, so I systematically added every jar in the "lib" and "ant/dep/lib" locations to the classpath explicitly.
It runs a bit without any issues (it's a setup batch, so in the first phase of the script, it uses a lot of "input" tasks), then I receive the message that org.apache.tools.ant.taskdefs.optional.PropertyFile was not found. Looking around, I discovered it was located in ant-nodeps.jar and I had added it to the class path, but no change.
Complete failure due to missing libraries I can understand, but why would the build partially function if I was sure I was including every library (including ant-nodeps.jar)?
The script file to launch it is as follows:
#!/QOpenSys/usr/bin/bsh
ANT_HOME=dep/ant
PARAMS="-Dant.home=$ANT_HOME -Dsystem.type=as400 -Dis-as400=y"
LIBS="lib/ant-contrib-1.0b3.jar:lib/ant-launcher.jar:lib/ant.jar:lib/catalina-ant.jar:lib/catalina-deployer.jar:lib/commons-net-2.2.jar:lib/el-api.jar:lib/ganymed.jar:lib/jakarta-oro-2.0.8.jar:lib/jasper-el.jar:lib/jasper.jar:lib/jsp-api.jar:lib/log4j-1.2.16.jar:lib/mail.jar"
ANTLIBS="$ANT_HOME/lib/ant-antlr.jar:$ANT_HOME/lib/ant-jai.jar:$ANT_HOME/lib/ant-starteam.jar:$ANT_HOME/lib/ant-apache-bcel.jar:$ANT_HOME/lib/ant-javamail.jar:$ANT_HOME/lib/ant-stylebook.jar:$ANT_HOME/lib/ant-apache-bsf.jar:$ANT_HOME/lib/ant-jdepend.jar:$ANT_HOME/lib/ant-swing.jar:$ANT_HOME/lib/ant-apache-log4j.jar:$ANT_HOME/lib/ant-jmf.jar:$ANT_HOME/lib/ant-testutil.jar:$ANT_HOME/lib/ant-apache-oro.jar:$ANT_HOME/lib/ant-jsch.jar:$ANT_HOME/lib/ant-trax.jar:$ANT_HOME/lib/ant-apache-regexp.jar:$ANT_HOME/lib/ant-junit.jar:$ANT_HOME/lib/ant-weblogic.jar:$ANT_HOME/lib/ant-apache-resolver.jar:$ANT_HOME/lib/ant-launcher.jar:$ANT_HOME/lib/ant.jar:$ANT_HOME/lib/ant-commons-logging.jar:$ANT_HOME/lib/ant-netrexx.jar:$ANT_HOME/lib/xercesImpl.jar:$ANT_HOME/lib/ant-commons-net.jar:$ANT_HOME/lib/ant-nodeps.jar:$ANT_HOME/lib/xml-apis.jar"
java -classpath $LIBS:$ANTLIBS $PARAMS org.apache.tools.ant.launch.Launcher -buildfile install/install.xml
Any help would be appreciated, even if only suggestions for what to try.
EDIT: In light of oers observation, I realized that there are shell scripts for ant afterall (have pity, I'm no expert in linux), so I'm going to attempt to use it to launch ant rather than try to do the same thing myself. I'll let everyone know of my progress and/or if I was able to fix it doing it that way.
I looked into the shellscript on my machine.
There is an additional parameter set:
-Dant.library.dir=\"$ANT_LIB\"
Perhaps this is needed?
ant_exec_command="exec \"$JAVACMD\" $ANT_OPTS
-classpath \"$LOCALCLASSPATH\"
-Dant.home=\"$ANT_HOME\"
-Dant.library.dir=\"$ANT_LIB\" $ant_sys_opts
org.apache.tools.ant.launch.Launcher
$ANT_ARGS
-cp \"$CLASSPATH\"
$ant_exec_args"
Using the ant scripts to launch the setup seemed to do the trick, specifying parameter -lib as lib and -buildfile as install/install.xml.

Executing a JAR on X startup

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.

Resources