Getting started with JavaCC - jar

I am new to JavaCC and cannot figure out how to get it running. I am using Mac OS X and I installed javacc-6.0.zip and unzipped it. I am unable to make the javacc script accessible from my path as on typing javacc on the terminal I get the following message:
-bash: javacc: command not found
How do I make the javacc script accessible from my path?
My unzipped folder javacc-6.0 is in the following directory: /Users/Rishabh/Desktop/javacc
So I do the following on the terminal:
PATH=$PATH\:/Users/Rishabh/Desktop/javacc/javacc-6.0/
Typing javacc next gives me the same message.

The version of JavaCC 6.0 that I downloaded today (2013.07.22) did not have a complete bin directory. It was missing all the script files! Hopefully this will be remedied soon.
For OS X and other unix/linux variants, the missing script file is called javacc, should be executable, and should contain the following:
#!/bin/sh
JAR="`dirname $0`/lib/javacc.jar"
case "`uname`" in
CYGWIN*) JAR="`cygpath --windows -- "$JAR"`" ;;
esac
java -classpath "$JAR" javacc "$#"
Add the bin directory to your PATH (omitting the backslash -- as pointed out by Ahmed Masud) and all should be ticketty boo. If your OS comes from Redmond or you want to run jjtree or jjdoc, just download javacc-5.0 and copy the script files (NOT the lib directory!!!!) from the 5.0 bin directory to the 6.0 bin directory.
Update (2020): Since version 6 is now harder to find, I have put a copy at www.engr.mun.ca/~theo/JavaCC/javacc-6.1.0.zip

In Windows, I also had no javacc and have to use
java -cp bin\lib\javacc.jar javacc
instead. This is very frustrating because all docs propose to use javacc, which we miss. Yet, I see that javacc was defined in the old javacc 5.0. I see javacc.bat there
java -classpath "%~dp0lib\javacc.jar;%~dp0lib\javacc.jar;%~f0\..\lib\javacc.jar" javacc %1 %2 %3 %4 %5 %6 %7 %8 %9

more javacc:
#!/bin/sh JAR="`dirname $0`/lib/javacc.jar"
case "`uname`" in
CYGWIN*) JAR="`cygpath --windows -- "$JAR"`" ;; esac
java -classpath "$JAR" javacc "$#"
more jjtree:
#!/bin/sh JAR="`dirname $0`/lib/javacc.jar"
case "`uname`" in
CYGWIN*) JAR="`cygpath --windows -- "$JAR"`" ;; esac
java -classpath "$JAR" jjtree "$#"
Create these scripts in the bin folder of your javacc-6.0/bin.
make a chmod :
chmod 755 javacc
chmod 755 jjtree

On Mac OS X & Linux I just use a single script and two symbolic links:
echo 'java -cp /path/to/javacc.jar $(basename $0) "$#"' > javacc
chmod 755 javacc
ln -s javacc jjtree
ln -s javacc jjdoc
The first two lines create the script and make it executable.
The second two lines reuse the javacc script for jjtree and jjdoc, since it all comes from the same JAR.

You need to first unzip the package, and add location where your javacc is located in your
PATH environment variable.
like:
set path=%path%;<location_of_your_javacc>;

Check if you have javacc and jjtree in the bin/ directory of your javacc-6.0.zip. When you get javacc6.0 from https://javacc.java.net/, this bin directory is empty.
javacc & jjtree are scripts.
Actually i'm using Java 5.0 and i'm modified my .profile file to add (I put javacc in my Applications folder):
export
PATH=/opt/local/bin:/opt/local/sbin:/Applications/javacc-5.0/bin/:$PATH
It's working perfectly.

Related

Why tmuxinator zsh complete file is not work?

According to the hint, I download the file
https://raw.githubusercontent.com/tmuxinator/tmuxinator/master/completion/tmuxinator.zsh
into /usr/local/share/zsh/site-functions/_tmuxinator(file path), but the autocompletion not work.
Then I source the file like below in ~/.zshrc, it is also not work.
. /usr/local/share/zsh/site-functions/_tmuxinator
My config environments are:
zsh: zsh 5.8 (x86_64-suse-linux-gnu)
tmuxinator: tmuxinator 2.0.1
And I use oh-my-zsh as my zsh environment and rbenv to install tmuxinator.
The fpath environment variable in my system is:
/home/run/.oh-my-zsh/plugins/git /home/run/.oh-my-zsh/functions /home/run/.oh-my-zsh/completions /usr/local/share/zsh/site-functions /usr/share/zsh/site-functions /usr/share/zsh//functions/Calendar /usr/share/zsh//functions/Chpwd /usr/share/zsh//functions/Completion /usr/share/zsh//functions/Completion/Base /usr/share/zsh//functions/Completion/Linux /usr/share/zsh//functions/Completion/Unix /usr/share/zsh//functions/Completion/X /usr/share/zsh//functions/Completion/Zsh /usr/share/zsh//functions/Completion/openSUSE /usr/share/zsh//functions/Exceptions /usr/share/zsh//functions/MIME /usr/share/zsh//functions/Math /usr/share/zsh//functions/Misc /usr/share/zsh//functions/Newuser /usr/share/zsh//functions/Prompts /usr/share/zsh//functions/TCP /usr/share/zsh//functions/VCS_Info /usr/share/zsh//functions/VCS_Info/Backends /usr/share/zsh//functions/Zftp /usr/share/zsh//functions/Zle /etc/zsh_completion.d
which includes the directory /usr/local/share/zsh/site-functions.
You may have to force rebuild zcompdump:
rm -f ~/.zcompdump; compinit

Creating Fat Jars: What is the mods folder?

I'm just on:
https://openjfx.io/openjfx-docs/#modular
trying to create a jar I can run on other systems (that do not have the javafx libraries as would happen with a non-developer layman user) and they've told me to use this:
dir /s /b src\*.java > sources.txt & javac --module-path %PATH_TO_FX% -d mods/hellofx #sources.txt & del sources.txt
What is mods/
Where is that supposed to be? Are they talking about out/ ?
The doc you have linked refers to this sample.
If you clone the sample, and follow instructions on how to compile and run the project, the first command can be divided in three parts:
dir /s /b src\*.java > sources.txt & \
javac --module-path %PATH_TO_FX% -d mods/hellofx #sources.txt & \
del sources.txt
The first part just gets all the Java files in the src path and adds that to sources.txt file:
C:\path\to\hellofx\src\module-info.java
C:\path\to\hellofx\src\hellofx\HelloFX.java
The second part calls the javac command (see reference) to compile the content of sources.txt, adding the required --module-path option to include the JavaFX modules, and also adding the output or destination -d option:
-d directory
Sets the destination directory for class files. If a class is part of a package, then javac puts the class file in a subdirectory that reflects the package name and creates directories as needed.
This means that we are going to compile hellofx.HelloFX.java into the directory mods/hellofx, resulting in:
C:\path\to\hellofx\mods\hellofx\module-info.class
C:\path\to\hellofx\mods\hellofx\hellofx\HelloFX.class
The third step will just remove the sources.txt file.
And now you can run your module:
java --module-path "%PATH_TO_FX%;mods" -m hellofx/hellofx.HelloFX
You can specify any directory for the output, of course, so you can change it to out or build for instance, but then make sure you modify it accordingly in the rest of the instructions.

Executing an executable must be done using a path. Why?

In the following:
Roberts-MacBook-Pro:Code robertnash$ mkdir Flag
Roberts-MacBook-Pro:Code robertnash$ cd Flag/
Roberts-MacBook-Pro:Flag robertnash$ swift package init --type executable
Roberts-MacBook-Pro:Flag robertnash$ swift build
Compile Swift Module 'Flag' (1 sources)
Linking ./.build/debug/Flag
In order to execute the executable, it must be a path, like so
Roberts-MacBook-Pro:Flag robertnash$ .build/debug/Flag
Hello, world!
If I go to where 'Flag' is located, the command cannot be run by simply typing 'Flag'.
Roberts-MacBook-Pro:Flag robertnash$ cd .build
Roberts-MacBook-Pro:.build robertnash$ cd debug
Roberts-MacBook-Pro:debug robertnash$ Flag
-bash: Flag: command not found
It must be a path, like so.
Roberts-MacBook-Pro:debug robertnash$ ./Flag
Why is that ?
If you run export PATH="$PATH:." then it will add the current working directory to your path and you won't need the ./ prefix. (Most (all?) shells accept just a trailing colon without the dot, but I find it's more explicit about what it does.)
This isn't present by default because it is a security risk: a malicious script could be named as something missing from your path, like nmap or even as a typo like sl, and placed in a directory in the hopes that you run it. Forcing you to prefix ./ is a good way of avoiding that.

How to extract a .tar.gz file on UNIX

I have a file (reviews_dataset.tar.gz) that contains many files which contains data. I am required to extract the files in this archive and then perform some basic commands on the file. So far I have created a directory named (CW) and found a command tar zxvf fileNameHere.tgz but when I run this it of course cannot find my file as I have not "downloaded it" into my directory yet? How do I get this file into my directory so that I can then extract it? Sorry if this is poorly worded I am extremely new to this.
You must either run the command from the directory your file exists in, or provide a relative or absolute path to the file. Let's do the latter:
cd /home/jsmith
mkdir cw
cd cw
tar zxvf /home/jsmith/Downloads/fileNameHere.tgz
You should use the command with the options preceded by dash like this:
tar -zxvf filename.tar.gz
If you want to specify the directory to save all the files use -C:
tar -zxf filename.tar.gz -C /root/Desktop/folder

Is it possible to create a symlink to the latest file in a directory?

I have a home directory in my unix box. I would like to setup a number or shortcuts in it to point to the latest file in another directory and the link will update if a newer file is created.
Is this possible?
So far I able to get the latest file:
ls -lrt | tail -n1
Thanks
[EDIT]
Perhaps I could even create a shell instead of a softlink which finds the latest file and returns it so I can open/grep/delete etc?
In bash, this will make a link to the latest file or directory in "target-directory" called "latest":
ln -s target-directory/`ls -rt target-directory | tail -n1` latest
And this will wait for a change in "target-directory" before returning:
inotifywait -e attrib target-directory

Resources