How to compile Jigsaw http server on Linux? - linux

I download the Jigsaw server source from w3c website, http://www.w3.org/Jigsaw/. I followed its instruction http://www.w3.org/Jigsaw/Doc/Programmer/compile.html, but still can not compile it on my linux. What does it mean to update your CLASSPATH to compile Jigsaw and use the new compiled classes? How could I set my classpath?
Plz give me some help.
Thanks.

It means you need to set the $CLASSPATH environment variable. I haven't looked at Jigsaw, but if you wanted to set your $CLASSPATH to include all the jar files within a directory (for example one that contains all the Jigsaw compiled jars) then you can use this script fragment:
CLASSPATH=""
for j in $(find /path/to/jigsaw/lib -name \*.jar)
do
if [ ! -z "$CLASSPATH" ]; then CLASSPATH="$CLASSPATH:"; fi
CLASSPATH="$CLASSPATH$j"
done
Now whenever you invoke the java command it will use the classes within /path/to/jigsaw/lib.
However this is not a good idea; better is to use the above technique to build an environment variable other than $CLASSPATH and pass that as the argument to the java -cp command line option:
cp=""
for j in $(find /path/to/jigsaw/lib -name \*.jar)
do
if [ ! -z "$cp" ]; then cp="$cp:"; fi
cp="$cp$j"
done
java -cp $cp ...

Related

Bash PATH entries duplicated

I use fedora Linux, I manually installed .net core, java and add the path to the PATH
Today, I checked my PATH and the output below, as you can see, jdk, dotnet and gradle entries are all duplicated. can someone tell me how to get this resolved please
/opt/jdk/bin:/opt/jdk/bin:/home/xxx/.local/bin:/home/xxx/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/opt/gradle/bin:/opt/dotnet:/opt/gradle/bin:/opt/dotnet
For readability:
/opt/jdk/bin:
/opt/jdk/bin:
/home/xxx/.local/bin:
/home/xxx/bin:
/usr/local/bin:
/usr/local/sbin:
/usr/bin:
/usr/sbin:
/opt/gradle/bin:
/opt/dotnet:
/opt/gradle/bin:
/opt/dotnet
below are the entries I added to my .bashrc file
# Java path settings
export JAVA_HOME=/opt/jdk
PATH=$JAVA_HOME/bin:$PATH
# gradle building system
PATH=$PATH:/opt/gradle/bin
# Disable dotnet Telemetry
export DOTNET_CLI_TELEMETRY_OPTOUT=1
# Dotnet path settings
export DOTNET_ROOT=/opt/dotnet
PATH=$PATH:$DOTNET_ROOT
export PATH
The system part of setting files that modify the PATH are /etc/bashrc and /etc/profile, they both have below quoted code. is this caused the duplication? but when I read the comment, /etc/bashrc need to redo this becasue pathmunge is unset at the end of /etc/profile
pathmunge () {
case ":${PATH}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
esac
}
Can someone help me out?
Thanks
B
I kinda live with it.
but I solved this by using the if, below is my solution
if ! [[ "$PATH" =~ "$JAVA_HOME/bin:/opt/gradle/bin:$DOTNET_ROOT:" ]]
then
PATH="$JAVA_HOME/bin:/opt/gradle/bin:$DOTNET_ROOT:$PATH"
fi
export PATH

How to use Sass with NetBeans on Linux / macOS

I used to be able to install and use Sass with NetBeans 8 as described in the top answer on How to use SASS with Netbeans 8.0.1
Now, with the current version of Sass (1.14.1), installing is different. Basically just download and untar. That's done and I've pointed NetBeans to the correct location. But this current version of Sass won't run correctly from NetBeans:
"/opt/dart-sass/sass" "--cache-location"
"/home/jasper/.cache/netbeans/8.2/sass-compiler"
"path_to_my.scss" "path_to_my.css"
Could not find an option named "cache-location".
This error is also covered by Sass output error in Netbeans 8.2 where they are using Windows.
I tried to add the cache location parameter (similar to the solution for Windows) to this line in the sass file:
exec "$path/src/dart" --no-preview-dart-2 "-Dversion=1.14.1" "$path/src/sass.dart.snapshot" "$#"
but I could not get it working (same error keeps appearing).
Anybody any ideas on how to get Sass 1.14.1 working from NetBeans 8.2 on Linux (Ubuntu)?
The issue is that --cache-location is no longer supported and should be removed. All of the original parameters are used by "$#". To remove the first two parameters, you should be able to use "${#:3}" (see Process all arguments except the first one (in a bash script)), but somehow that resulted into a "Bad substitution" error for me. So I opted to use shift 2 to remove them:
#!/bin/sh
# Copyright 2016 Google Inc. Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.
# This script drives the standalone Sass package, which bundles together a Dart
# executable and a snapshot of Sass. It can be created with `pub run grinder
# package`.
follow_links() {
file="$1"
while [ -h "$file" ]; do
# On Mac OS, readlink -f doesn't work.
file="$(readlink "$file")"
done
echo "$file"
}
# Unlike $0, $BASH_SOURCE points to the absolute path of this file.
path=`dirname "$(follow_links "$0")"`
shift 2
exec "$path/src/dart" --no-preview-dart-2 "-Dversion=1.14.1" "$path/src/sass.dart.snapshot" "${#}"
Make sure to keep the original file and create a copy to only be used with NetBeans and make the change there.
macOS (Home Brew)
If you are looking for the Dart Sass install location (after installing it with Home Brew), it is located here:
/usr/local/Cellar/sass/{version}/bin
macOS (node.js)
When using node.js, you will run into the "env: node: No such file or directory" issue.
To work around that I created (make sure you make it executable (chmod a+x)):
/usr/local/lib/node_modules/sass/sass_nb.sh
and added:
#!/bin/zsh
export PATH="$PATH:"/usr/local/bin/
shift 3
sass ${#}
NetBeans 11+
On NetBeans 11 and 12 I had to use shift 3 instead of shift 2.
My response is based heavily on Jasper de Vries'one:
It seems that Netbeans simply adds some additional parameters that are no longer supported by sass compiler.
In my case the complete command issued by Netbeans was:
"/home/alex/tools/dart-sass/sass" "--cache-location" "/home/alex/snap/netbeans/common/cache/12.0/sass-compiler" "--debug-info" "/home/alex/projects/alexgheorghiu.com/web/aaa.scss" "/home/alex/projects/alexgheorghiu.com/web/aaa.css"
So the first 3 parameters
"--cache-location" "/home/alex/snap/netbeans/common/cache/12.0/sass-compiler" "--debug-info"
must be "deleted" or ignored.
So you need to either alter the sass file or make a copy of it (safest way)
and add
shift 3
instruction.
So if you start from original version like:
#!/bin/sh
# This script drives the standalone dart-sass package, which bundles together a
# Dart executable and a snapshot of dart-sass.
follow_links() {
file="$1"
while [ -h "$file" ]; do
# On Mac OS, readlink -f doesn't work.
file="$(readlink "$file")"
done
echo "$file"
}
# Unlike $0, $BASH_SOURCE points to the absolute path of this file.
path=`dirname "$(follow_links "$0")"`
exec "$path/src/dart" "$path/src/sass.snapshot" "$#"
You need to end up with something like:
#!/bin/sh
# This script drives the standalone dart-sass package, which bundles together a
# Dart executable and a snapshot of dart-sass.
follow_links() {
file="$1"
while [ -h "$file" ]; do
# On Mac OS, readlink -f doesn't work.
file="$(readlink "$file")"
done
echo "$file"
}
# Unlike $0, $BASH_SOURCE points to the absolute path of this file.
path=`dirname "$(follow_links "$0")"`
shift 3
exec "$path/src/dart" "$path/src/sass.snapshot" "$#"
An interesting aspect is that this bug is known by Netbeans developers (See: Could not find an option named "cache-location") but I was not able to achieve that because under my Xubuntu 18 the Netbeans is a "snap" and therefore it's netbeans.conf file is read only.
But in case you CAN modify that file it might be a cleaner solution.

Compiling static library for Google Native Client using SCons

I'm working on a few multi platform projects that all depend on common framework.
I want to add support for Google Native-Client (NaCl). The way I aproached the problem is first to compile the framework as static library (this is how I've been doing it on all other platforms).
I have to say that I have never used SCons before. I think I start grasping it. Starting from a build.scons from a tutorial I can get some code compiling and linking. Now I would want to skip the linking process but seems like the nacl_env was never intended to compile static libraries.
Reading the SCons help didn't help me much since the Library node is missing from the nacl_env.
I don't think I understand SCons enough to write the whole build process from scratch so I was hopping to not have to do so.
1. Am I approaching the problem correctly?
2. Any tips or sample nacl static libs, build using SCons?
Ok, what I did is way more trickery than what you probably need.
I wanted my static library to handle the initialization steps of the NaCl module, and then call some project-specific function.
I ended up turning my whole framework and the contents of the built-in libppapi_cpp.a into a single .o file, and then that into a single .a file, a static library.
I needed a single .o file, because otherwise I would run into dependency problems releated to initialization, I could not solve.
build_lib.sh (framework):
#!/bin/bash -e
SDK="/home/kalmi/ik/nacl_sdk/pepper_15"
function create_allIn_a {
TMPDIR="`mktemp -d`"
echo $TMPDIR
cp $O_FILES $TMPDIR
pushd $TMPDIR &> /dev/null
$AR x $LIBPPAPI_CPP_A
$LD -Ur * -o ALL.o
$AR rvs $OUTPUT_NAME ALL.o
$RANLIB $OUTPUT_NAME
popd &> /dev/null
}
./scons
BIN_BASE="$SDK/toolchain/linux_x86/bin"
LD="$BIN_BASE/i686-nacl-ld"
AR="$BIN_BASE/i686-nacl-ar"
RANLIB="$BIN_BASE/i686-nacl-ranlib"
LIBPPAPI_CPP_A="$SDK/toolchain/linux_x86_newlib/x86_64-nacl/lib32/libppapi_cpp.a"
O_FILES="`find $(pwd)/opt_x86_32 | grep .o$ | grep --invert-match my_main.o | tr "\n" " "`"
LIBDIR="../../../bin/lib/lib32"
mkdir -p $LIBDIR
if [ -f $LIBDIR/libweb2grid_framework.a ]; then
rm $LIBDIR/libweb2grid_framework.a
fi
OUTPUT_NAME="`readlink -m $LIBDIR/libweb2grid_framework.a`"
create_allIn_a
BIN_BASE="$SDK/toolchain/linux_x86/bin"
LD="$BIN_BASE/x86_64-nacl-ld"
AR="$BIN_BASE/x86_64-nacl-ar"
RANLIB="$BIN_BASE/x86_64-nacl-ranlib"
LIBPPAPI_CPP_A="$SDK/toolchain/linux_x86_newlib/x86_64-nacl/lib64/libppapi_cpp.a"
O_FILES="`find $(pwd)/opt_x86_64 | grep .o$ | grep --invert-match my_main.o | tr "\n" " "`"
LIBDIR="../../../bin/lib/lib64"
mkdir -p $LIBDIR
if [ -f $LIBDIR/libweb2grid_framework.a ]; then
rm $LIBDIR/libweb2grid_framework.a
fi
OUTPUT_NAME="`readlink -m $LIBDIR/libweb2grid_framework.a`"
create_allIn_a
./scons -c
The my_main.o file is excluded from the static library, because that file contains the function that is to be provided by the project that uses this framework.
The build.scons file for the framework is truly ordinary.
build.scons (for some project that uses this framework):
#! -*- python -*-
#What to compile:
sources = [ 'src/something.cpp', 'src/something_helper.cpp' ]
###############################################################x
import make_nacl_env
import nacl_utils
import os
nacl_env = make_nacl_env.NaClEnvironment(
use_c_plus_plus_libs=False,
nacl_platform=os.getenv('NACL_TARGET_PLATFORM'))
nacl_env.Append(
# Add a CPPPATH that enables the full-path #include directives, such as
# #include "examples/sine_synth/sine_synth.h"
CPPPATH=[os.path.dirname(os.path.dirname(os.path.dirname(os.getcwd())))],
LIBS=['web2grid_framework','srpc'],
LIBPATH=['../../../bin/lib/lib32','../../../bin/lib/lib64'],
LINKFLAGS=['-pthread']
)
nacl_env.AllNaClModules(sources, 'client')
Some lines worth highlighting:
use_c_plus_plus_libs=False,
LIBS=['web2grid_framework','srpc'],
LIBPATH=['../../../bin/lib/lib32','../../../bin/lib/lib64'],
LINKFLAGS=['-pthread']
I am not saying that this is a clean method, but it gets the job done.
So, there's two questions here
1. Using SCONS:
NaCl uses SCONS for it's examples, simply to help compiling of the examples easier. In reality, SCONS simply directs to the GCC/G++ compilers in the SDK build directories. (SCONS will take the input scripts, and create the final param string to send to GCC)
GCC is a common compiler, and is well documented on the net : http://gcc.gnu.org/
How you integrate NaCl compilation into your work-flow is up to you (ie you're not forced to use SCONS).
For instance, if you'd like to go to GCC directly, you can simply call :
<path to bin>/x86_64-nacl-gcc -m64 -o test.nexe main.c
For a more detailed look into how to compile NaCl modules, please read the documentation # gonacl.com on compiling which will detail how to compile with and without SCONS.
2.Compilng Static libs with GCC
Here is an example : http://www.adp-gmbh.ch/cpp/gcc/create_lib.html
~Main

LD_LIBRARY_PATH : how to find a shared object

I have a shared object ( libxyz.so ). Given LD_LIBRARY_PATH, how can find the exact location of this shared object? If i had a binary that depends on this lib, i would have used ldd on that.
Here is the reason why i ask:
I have a cgi script which works when using LD_LIBRARY_PATH set to say VALUE1. It does not work when the path is set to VALUE2. I would like to find the exact location of the library as specified by the path in VALUE1 ( Note that VALUE1 has almost 20+ different locations )
Platform: Linux
Put this in a file:
#!/bin/bash
IFS=:
for p in ${LD_LIBRARY_PATH}; do
if [ -e ${p}/libxyz.so ]; then
echo ${p}
fi
done
and run it.
You can also use ldd. To do this, you would:
Set LD_LIBRARY_PATH to the value when it works (i.e. export LD_LIBRARY_PATH=VALUE1)
Run ldd /path/to/prog | grep libxyz.so
put a sleep(30); in your cgi, launch it from a browser, then look into /proc/$(pidof mycgi)/maps for actual libs used by your program.

How do you configure GroovyConsole so I don't have to import libraries at startup?

I have a groovy script that uses a third party library. Each time I open the application and attempt to run my script I have to import the proper library.
I would like to be able to open GroovyConsole and run my application without having to import the library.
In Linux you also have
/usr/share/groovy/conf/groovy-starter.conf
Here you can add your specific libs:
# load user specific libraries
load !{user.home}/.groovy/lib/*.jar
load /home/squelsh/src/neo4j-community-1.4.M03/lib/*.jar
load /home/squelsh/src/neo4j-community-1.4.M03/system/lib/*.jar
Hope it helps, had to search long time to find this (:
If you just want to add the JARs to the classpath, copy (or symlink) them to ~/.groovy/lib (or %USER_HOME%/.groovy/lib on Windows).
If you want the actual import statements to run every time Groovy Console starts, edit the groovy-starter.conf file as suggested by Squelsh.
At least on Linux groovy GroovyConsole is a Script has the Following command:
startGroovy groovy.ui.Console "$#"
startGroovy itself is a script which starts Java. Within the startGroovy script you should be able to modify your classpath and add the missing librarys.
From startGroovy:
startGroovy ( ) {
CLASS=$1
shift
# Start the Profiler or the JVM
if $useprofiler ; then
runProfiler
else
exec "$JAVACMD" $JAVA_OPTS \
-classpath "$STARTER_CLASSPATH" \
-Dscript.name="$SCRIPT_PATH" \
-Dprogram.name="$PROGNAME" \
-Dgroovy.starter.conf="$GROOVY_CONF" \
-Dgroovy.home="$GROOVY_HOME" \
-Dtools.jar="$TOOLS_JAR" \
$STARTER_MAIN_CLASS \
--main $CLASS \
--conf "$GROOVY_CONF" \
--classpath "$CP" \
"$#"
fi
You can write an external Groovy script that does all the imports, creates a GroovyConsole object, and calls the run() method on this object.
See also http://groovy.codehaus.org/Groovy+Console#GroovyConsole-EmbeddingtheConsole
For example: start.groovy
import groovy.ui.Console;
import com.botkop.service.*
import com.botkop.service.groovy.*
def env = System.getenv()
def service = new ServiceWrapper(
userName:env.userName,
password:env.password,
host:env.host,
port:new Integer(env.port))
service.connect()
Console console = new Console()
console.setVariable("service", service)
console.run()
From a shell script call the groovy executable providing it with the groovy script:
#!/bin/bash
if [ $# -ne 4 ]
then
echo "usage: $0 userName password host port"
exit 10
fi
export userName=$1
export password=$2
export host=$3
export port=$4
export PATH=~/apps/groovy/bin:/usr/bin:$PATH
export CLASSPATH=$(find lib -name '*.jar' | tr '\n' ':')
groovy start.groovy
The code in GroovyConsole can now make use of the imports done in start.groovy, as well as of the variables created and passed with the setVariable method ('service' in the example).
If you are on a Mac, I would highly recommend using SDKMAN to manage Groovy installations.
Once installed via SDKMAN, you can modify ~/.sdkman/candidates/groovy/current/bin/groovy/conf/groovy-starter.conf. Packages you add here will be automatically imported at runtime whenever you start a Groovy Console session. You would want to add them under the section labelled in the example below:
# load user specific libraries
load !{user.home}/.groovy/lib/*.jar
load !{user.home}/.groovy/lib/additional_package.jar

Resources