How to install tomcat with a specific PATH under Windows? - windows

I have the following Code:
tomcat5.exe //IS//%SERVICE_NAME% --StartPath "%BASE_DIR%\bin" --Jvm "%JAVA_HOME%\bin\%JAVA_MODE%\jvm.dll" --StartClass org.apache.catalina.startup.Bootstrap --StopClass org.apache.catalina.startup.Bootstrap --StartParams "-config;%CONFIG%;start" --StopParams stop --Startup auto
tomcat5.exe //US//%SERVICE_NAME% --JvmOptions "-Dcatalina.base=%CATALINA_BASE%#-Dcatalina.home=%CATALINA_HOME%#-Djava.endorsed.dirs=%CATALINA_HOME%\common\endorsed#-Xrs#-Djava.library.path=%DLL_DIR%#-DimageservicePath=%imageservicePath%" --StartMode jvm --StopMode jvm
tomcat5.exe //US//%SERVICE_NAME% ++JvmOptions "-Djava.io.tmpdir=%CATALINA_BASE%\temp"
tomcat5.exe //US//%SERVICE_NAME% --JvmMx %MEMORY% --JvmMs %MIN_MEMORY%
tomcat5.exe //US//%SERVICE_NAME% --Environment "PATH=.\;c:\path\bin"
I need to specify a special PATH, because some native-code loading issues.
My problem is, that the service-installer will change provided PATH:
http://tomcat.apache.org/tomcat-5.5-doc/windows-service-howto.html
--Environment
List of environment variables that will be provided to the service in the form key=value. They are separated using either # or ; characters
I need to specify a Windowes PATH with two locations: PATH=.;c:\path\bin
The path will be stored within the registry:
PATH=.
c:\path\bin
it should be:
PATH=.;c:\path\bin
It works as described, so I think I missed something, but I did not find anything about how to set the PATH and solve this issue...
PS:
I know I'm using an outdated version of tomcat.

Well, after I downloaded the source and figured out, that the apache-commons procrun deamon is used and I finally found the solution. The documentation at the tomcat project wasn't complete:
http://commons.apache.org/daemon/procrun.html
++Environment
List of environment variables that will be provided to the service in the form key=value. They are separated using either # or ; characters. If you need to embed either # or ; character within a value put them inside single quotes.
The last sentence lead to the solution:
"%EXECUTABLE%" //US//%SERVICE_NAME% --Environment "PATH='%PATH%'"

Related

TOMCAT: quote < ' > in CATALINA_HOME environment variable causing load error?

I'm trying to install tomcat as a service using service.bat in the following path :
C:\Program Files\text with' quote\Tomcat
but I keep getting the following error :
java.io.FileNotFoundException: C:\Program Files\text with quote\Tomcat\conf\logging.properties; (The system cannot find the path specified)
as you can see from the error message the ' is being ignored and thus keeping some files from being found/loaded properly.
If I switch to a path without a quote, everything works well. Is there a way around this as I need to include a ' in the path?
Your problem comes from the way Procrun parses its command line parameters. In those parameters which accept lists of values (++DependsOn, ++Environment, ++JvmOptions, ++JvmOptions9, ++StartParams and ++StopParams) single quotes ' are stripped after the parameter value has been split into single values. There is no way to quote them (cf. source code).
Therefore the ++JvmOptions parameter used in service.bat is interpreted as follows (one value per line):
-Dcatalina.home=C:\Scarlett oHara;-Dcatalina.base=C:\Scarlett oHara
-Dignore.endorsed.dirs=C:\Scarlett oHara\endorsed;-Djava.io.tmpdir=C:\Scarlett oHara\temp
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.util.logging.config.file=C:\Scarlett oHara\conf\logging.properties;
You might notice that some entries are joined by ;, due to the ' unintentional quoting.
The only way to fix this is to start Prunmgr (the executable renamed as tomcat*w.exe) and fix them in the "Java" tab:
-Dcatalina.home=C:\Scarlett o'Hara
-Dcatalina.base=C:\Scarlett o'Hara
-Dignore.endorsed.dirs=C:\Scarlett o'Hara\endorsed
-Djava.io.tmpdir=C:\Scarlett o'Hara\temp
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.util.logging.config.file=C:\Scarlett o'Hara\conf\logging.properties;
or work directly on the HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Apache Software Foundation\Procrun 2.0 registry keys.
See also:
a similar problem due to quoting: Adding multiple values to an environment in registry and retrieving in Java application

Set spark.local.dir to different drive

I'm trying to setup standalone Spark on Windows 10. I would like to set spark.local.dir to D:\spark-tmp\tmp, as currently it appears to be using C:\Users\<me>\AppData\Local\Temp, which in my case is on an SSD drive which might not have enough space given the size of some datasets.
So I changed the file %SPARK_HOME%\conf\spark-defaults.conf to the following, without success
spark.eventLog.enabled true
spark.eventLog.dir file:/D:/spark-tmp/log
spark.local.dir file:/D:/spark-tmp/tmp
I also tried to run %HADOOP_HOME\bin\winutils.exe chmod -R 777 D:/spark-tmp, but it didn't change anything.
The error that I get is the following:
java.io.IOException: Failed to create a temp directory (under file:/D:/spark-tmp/tmp) after 10 attempts!
If I start the path with file://D:/... (note the double slash) nothing changes. If I remove the scheme at all, a different exception says that the scheme D: is not recognized.
I also noticed this warning:
WARN SparkConf:66 - In Spark 1.0 and later spark.local.dir will be overridden by the value set by the cluster manager (via SPARK_LOCAL_DIRS in mesos/standalone and LOCAL_DIRS in YARN).
So I tried to put the following line in %SPARK_HOME%\conf\spark-env.sh:
SPARK_LOCAL_DIRS=file:/D:/spark-tmp/tmp
If I put this line and comment the spark.local.dir line in the .conf file, Spark works perfectly, but the temporary files are still saved in my AppData\Local\Temp folder. So the SPARK_LOCAL_DIRS line is not read.
What's strange is that, if I let it run, it actually puts logs in D:/spark-tmp/log, which means that it's not a problem of syntax or permissions.
On windows you will have to make those environment variables
Add the key value pair
SPARK_LOCAL_DIRS -> d:\spark-tmp\tmp
to your systems environment variables

Apache 403 on windows using AliasMatch and -D

After i packaged apache to be portable (used any where), I had the surprise to get 403 error on AliasMatch but not on regular Location resources.
Update: I found the fix. Check answer.
And so, here is my own response.
I check the error.log and saw the path of the aliasmatch was wrong ( what a scoop). But note this path is made using a variable. Actually, all the character / that we can expect have been removed.
I look to the origin of the variable but not at the beginning, because all URI based on Location was working. Amazing ! But , the fact is, Location directive seems to convert the ugly \ windows in / to work, but not the AliasMatch directive. I forget to tell that i launched Apache using command line httpd with option -D and ... an ugly windows path with \ and not /. So, i convert the path in a pretty unix path and all is back in order.
In dos command : SET APACHE_ROOT="%THE_WINDOWS_PATH:\=/%"

How to run javac with paths as argument that contain white spaces?

I am trying to run the following
javac -Xlint:unchecked -classpath C:/Users/a b/workspace/ #C:/Users/a b/workspace/files_to_compile
but I'm getting a
javac: invalid flag C:/users/a
I've also tried to surround both paths with double quotes but it doesn't seem to help a bit:
javac -Xlint:unchecked -classpath "C:/Users/a b/workspace/" #"C:/Users/a b/workspace/files_to_compile"
What am I doing wrong? This same code worked correctly in other computers (probably because they didn't have any white space in their paths..).
Thanks
I've finally come up with the solution to the issue, and I guess no one here could have guessed it.
The cue to the answer lies with the fact that the contents of the files list (signaled as # in the args) generally will have each one of its strings with the initial substring equal to what one passes as both the class path and the # file.
so..
The trouble was never the command line parameters, as suggested, but with the contents of the # file.
Each line of the file must be put in its own line, surrounded by quotes, and having into consideration that if you're in windows, you have to put the file names in the form of C:\\a\\b\\c.txt!!!
Your second try is right
javac -Xlint:unchecked -classpath "C:/Users/a b/workspace/" #"C:/Users/a b/workspace/files_to_compile"
But to be complete, you have to escape the spaces into the text file "files_to_compile" by using:
the same syntax as properties file : \
or
double quote each line
I suggest the second but I'm not sure.
I have to admit this was more difficult than I had imagined.
After some trial and error I came up with the following:
C:\lol>"C:\Program Files\Java\jdk1.7.0_07\bin\javac" -cp "c:\lol\a b;c:\lol\foo bar" Lol.java
where the folder structure is like:
./foo bar
./foo bar/Moo.java
./Lol.java
./a b
./a b/AB.java
I made an archive with the folders and the java files, which you can grab at:
http://www.pvv.ntnu.no/~rakhmato/tmp/lol.tar
You should ignore the # option because it is enough to give the compiler one file and a proper class path, it can figure out where everything is on its own. Just give the compiler your Main.java and it will figure out what that file depends on.
I would also recommend you to write a .bat script of sorts to make things simpler. Nothing fancy, something like this:
compile.bat:
"C:\Program Files\Java\jdk1.7.0_07\bin\javac" -classpath "c:\lol\a b;c:\lol\foo bar" Main.java
..put that in your project folder and run compile.bat from CMD
First using the cd command in shell shift your directory to the one where your file is saved.
cd /home/sayantani/PERSONAL\ FILES/sem\ 4\ courses/PLC/code/
Note that I've used "\" whenever there is space involved. "PERSONAL FILES" becomes "PERSONAL\ FILES".
Then use "javac filename.java"
javac hello1.java
This should fix your problem.
Note that doing "javac" on the entire path from the default directory isn't working.(for me)
You need to escape spaces.
Put a \ in front of each space and try that.
Its taking only the 1st part of the Source String remove the space between a b from the path and it should work fine C:/Users/a_b/workspace/" #"C:/Users/a_b/workspace/files_to_compile" . Never you should have spaces in the path else the latter part will be ignored by the compiler or else you can put a '\' between a\ b
Bit of a hack, but if you're on Windows 7 you can get around this using the mklink utility to create another folder pointing to the same place, but without spaces.
Edit: perhaps a better solution:
cd "C:/Users/a b/"
javac ... -classpath "Workspace" ...
From usage info for "java /?"
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>cd "C:\Program Files (x86)\Java\jre6\bin"
C:\Program Files (x86)\Java\jre6\bin>java.exe
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-classpath indicates that you need to use a semi-colon (";") for multiple paths.
I can't test it but I'd suggest the following (as dmcgil suggested semicolon should be classpath separator on windows):
javac -Xlint:unchecked -classpath C:\Users\a^ b\workspace\;C:\Users\a^ b\workspace\files_to_compile
It seems that the escape charachter for win shell is caret.
That is also suggested here.
EDIT:
Also, in your question, I noticed usage of slashes (/) in paths, doesn't all versions of windows use backslashes(\) as file separators? I saw your comment somewhere on this thread stating just that, so I'll suppose you typoed in question.

Groovy not reading jar files in .groovy/lib

I'm having a problem with jar files and groovy. For a few specific examples I'm trying to connect to a postgresql database and when using
sql = Sql.newInstance("jdbc:postgresql://localhost", "user", "pass", "org.postgresql.Driver")
I get a ClassNotFound exception for org.postgresql.Driver. I have the postgresql jar in my ${user.home}/.groovy/lib, and the line to load from there in the groovy-starter.conf is not commented out. I'm also having a similar problem with a dbunit.jar file.
If I try to manually add the classpath using groovy -cp I'm getting an error that says
Caught: java.io.UnsupportedEncodingException: p
Any ideas?
According to the CLI Help - http://groovy.codehaus.org/Groovy+CLI:
$groovy -help
usage: groovy
-a,--autosplit <splitPattern> automatically split current line
(defaults to '\s')
-c,--encoding <charset> specify the encoding of the files
-e <script> specify a command line script
-h,--help usage information
-i <extension> modify files in place
-l <port> listen on a port and process inbound lines
-n process files line by line
-p process files line by line and print result
-v,--version display the Groovy and JVM versions
groovy -cp will tell groovy to load characterset p which does not exist.
Your attempt to use ${user.home}/.groovy/lib should have worked assuming you used the correct path for ${user.home}. If you add info on your OS we might see if you got it right or not.
As a WA - just export the CLASSPATH environment variable to wherever the jars are located.
Windows: set CLASSPATH=c:\temp\postgresql.jar;c:\temp\dbunit.jar ...
Unix/Linux (KSH): export CLASSPATH=${HOME}/temp/postgresql.jar:${TEMP}/temp/dbunit.jar ...

Resources