Change maven settings.xml location and pass -s automatically - bash

Intro
I moved my settings.xml file to a secured network share which only I can access.
The next step is to encrypt various credentials inside the file as well.
Unfortunately, now when I run mvn I need to specify the location every time, e.g.:
mvn -s Z:\CONFIG\settings.xml
Solution Try - Aliases
I tried making an alis in CMDER but I always get a goal not specfied error.
E.g. in user_aliases.cmd I add the following tries:
mvn1=echo "Using custom cmder alias (cmder user_aliases.cmd) : mvn -s Z:\CONFIG\settings.xml " & mvn -s Z:\CONFIG\settings.xml
mvn2=mvn -s Z:\CONFIG\settings.xml
They both fail with an error about goals not being passed.
So this is an issue with the arguements not being passed.
Anyone have a solution for hardcoding this location permanently???
Update
My current solution has been to edit the mvn.cmd file itself.
I added something like the following, and it works.....
though it breaks mvn for anyone else wanting to use it:
echo "Modified mvn.cmd to add custom path mvn -s Z:\CONFIG\settings.xml "
"%JAVACMD%" ^
%JVM_CONFIG_MAVEN_PROPS% ^
%MAVEN_OPTS% ^
%MAVEN_DEBUG_OPTS% ^
-classpath %CLASSWORLDS_JAR% ^
"-Dclassworlds.conf=%MAVEN_HOME%\bin\m2.conf" ^
"-Dmaven.home=%MAVEN_HOME%" ^
"-Dlibrary.jansi.path=%MAVEN_HOME%\lib\jansi-native" ^
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
%CLASSWORLDS_LAUNCHER% -s Z:\CONFIG\settings.xml %MAVEN_CMD_LINE_ARGS%
if ERRORLEVEL 1 goto error
goto end
I could possibly make a copy of maven to my Z drive (secured) and call that to avoid all of this.

I tried two solutions which both worked:
Move maven to folder with permissions
One solution was to move maven directly to a protected isolated folder such a shared network folder (with appropriate permissions) or user folder.
Edit the mvn cmd file
I edited the mvn.cmd file itself.
I added something like the following, and it works.....
WARNING: it breaks mvn for anyone else wanting to use it. So use only if this is not a consideration.
echo "Modified mvn.cmd to add custom path mvn -s Z:\CONFIG\settings.xml "
"%JAVACMD%" ^
%JVM_CONFIG_MAVEN_PROPS% ^
%MAVEN_OPTS% ^
%MAVEN_DEBUG_OPTS% ^
-classpath %CLASSWORLDS_JAR% ^
"-Dclassworlds.conf=%MAVEN_HOME%\bin\m2.conf" ^
"-Dmaven.home=%MAVEN_HOME%" ^
"-Dlibrary.jansi.path=%MAVEN_HOME%\lib\jansi-native" ^
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
%CLASSWORLDS_LAUNCHER% -s Z:\CONFIG\settings.xml %MAVEN_CMD_LINE_ARGS%
if ERRORLEVEL 1 goto error
goto end

Related

Windows CMD Line - Syntax Error- Parameter format not correct when trying to run command "del ..\C\D"

I have 4 folders, with A being the parent, B and C being the child of A, and D being the child of C.
A -> B
A -> C -> D
In folder B I want to generate a build via NPM and then to move the new folder over to D after deleting the previous version.
So to do this I'm trying to run the following script in the command line:
react-scripts build && rd /s/q ../C/D && move build ../C/D
Upon running this command however, I receive the following error:
Parameter format not correct - "C".
What is causing this error in particular and what would be the proper syntax to run this command?
Windows cmd prompt often requires paths to be in double quotes.
C:\Users\Me>mkdir c/d
The syntax of the command is incorrect.
C:\Users\Me>mkdir "c/d"
Windows powershell will accept the paths without quotes.
PS C:\Users\Gordon> mkdir c/d
Directory: C:\Users\Me\c
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 7/20/2022 11:51 AM d
In your example, just swap / (forward slash) with \ (backward slash) and you would probably be good to go...
react-scripts build && rd \s\q ..\C\D && move build ..\C\D
If your folder or file has empty spaces in the name you'd want to surround it with quotes.

Jasmine-node CLI: Specify file match parameter

I'm trying to execute just a subset of my node jasmine tests.
I have a project structure as follows
root
+ server
+ invite
+specs
inviteSendSpec.js
inviteConfirmSpec.js
.. many more spec files
+ auth
+specs
.. many spec files
I can execute all tests from root by running:
node-jasmine --verbose server/
I'm trying to figure out how to use the -m parameter, so that I can just run the test matching a certain file name pattern.
e.g.
node-jasmine --verbose -m invite server/
should run all tests which contain invite, according to the few examples I've found. But instead it just finds one single test.
If I try to run a similar variation e.g.
node-jasmine --verbose -m send server/
it will find no tests.
What is the correct syntax for selecting a subset of tests?
p.s. I'm running jasmine-node 11.1.0 (so its not the walkdir issue)
-m or --match parameter is indeed used for file name matching.
I banged my had against the keyboard for couple of hours, and ended up looking at source for cli.js.
So here is the ticket (cli.js, line 228):
var regExpSpec = new RegExp(match + (matchall ? "" : "spec\\.") + "(" + extensions + ")$", 'i')
Aha!
First, you MUST specify --matchall key, otherwise it will use default "spec" prefix.
Second, there is no way you can specify extensions, they are either js or js|coffee|litcoffee if you use --coffee command line parameter
My test files have unit.js suffix (do not ask why), so I ended up with
cli.js --verbose --matchall --match unit\. --test-dir C:\MyProject\
and it did the job.
Your file names are right and
from the docs github.com/mhevery/jasmine-node
Note: your specification files must be named as *spec.js, *spec.coffee
or *spec.litcoffee, which matches the regular expression
/spec.(js|coffee|litcoffee)$/i; otherwise jasmine-node won't find
them! For example, sampleSpecs.js is wrong, sampleSpec.js is right.
You just need to run the hole folder:
node-jasmine --verbose server/invite/specs/
node-jasmine --verbose server/auth/specs/

Batch file written in notedpad with '>' shows '1>' in dos windows.

I am trying to log an output from MSDeploy command line script to a log file.
:: SYNC FILES--
"C:\Program Files\IIS\Microsoft Web Deploy V2\msdeploy.exe" -Verb:sync ^
-Source:AppHostConfig=Website1,ComputerName=Server1 ^
-Dest:AppHostConfig=Website1,ComputerName=Server2 ^
-Skip:SkipAction='Update',objectName=filePath,absolutePath=.*web.config$ ^
-Skip:SkipAction='Update',ObjectName=contentPath,absolutePath=c:\\inetpub\\apppools ^
-Skip:objectName=Binding ^
-EnableRule=DoNotDeleteRule > msdeploy.log
TIMEOUT /T 100
"> msdeploy.log" shows up as "1> msdeploy.log" and becomes unable to log anything.
Any help will be appreciated ?
The redirection with > is the short form of 1>, to redirect stream1.
This is not your problem.
But it could be a directory problem, so the file is created but not in the expected one.
This happens when the working directory is not the same as the directory where the batch resides.

How to generate a indeterminate number of WAR files using Maven?

I would like to generate multiple WAR files, during the build cycle of my project. I already know how to add multiple dest-file, and other configuration with the maven-war-plugin. But I want to know if there is way to generate an indeterminate number of war during the build cycle, without writing configuration for each WAR.
I want to generate a build for each clients, I have the following directory structure in my project:
| pom.xml
+ src
+ main
+ clients
+ client1
+ client2
+ client3
+ ...
+ clientn
I would like to know how to generate a WAR for each client directory. I just want to create a Maven configuration, then just care about adding a new folder then mvn package and get n WAR packages.
Is it possible?
Seems like Maven cannot do that by itself, so I ended up creating a script that invoke Maven for each folder found in src/main/clients.
In Unix
#!/bin/bash
clear
###
# Check for Apache Maven home environment variable.
###
M2_HOME=`$M2_HOME`
if [ -z "$M2_HOME" ]; then
echo "Error: M2_HOME variable not set. Please set Apache Maven home."
exit
fi
###
# Build all client packages.
###
echo "Build start."
for f in $0/src/main/clients/*
do echo Building: %f
$M2_HOME/bin/mvn package -Dclient.id=`basename $f` -Dclient.path=$f -DskipTests
done;
echo "Build end."
In Windows
#ECHO off
SET M2_HOME=%M2_HOME%
CD %~p0
ECHO Build start.
FOR /r /d %%G in (src\main\client\*) DO (
ECHO Building: %%~nG
%M2_HOME%\bin\mvn package -Dclient.id=%%~nG -Dclient.path=%%G -DskipTests
)
ECHO Build end.

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.

Resources