Custom classpath for a CommandBox server instance

217 views
Skip to first unread message

Dave Merrill

unread,
Oct 21, 2016, 9:21:22 AM10/21/16
to CommandBox
Think I asked this before a long time ago, but might as well check for current CB. Is there any way to define a custom classpath for a CommandBox server instance? An app I work on has a lot of Java, and as you probably know, JavaLoader isn't a completely transparent solution at scale, so we actually need to add our dir to the classpath for the server instance. Simple for static servers, would be super awesome if you could do that for CB instances.

Thanks.

harbori...@gmail.com

unread,
Oct 21, 2016, 10:14:41 AM10/21/16
to CommandBox
You should be able to do that with the jvmargs parameter on the server start command. I haven't tried it myself but I think that's your best bet.

Server start jvmArgs=

I'm not an expert so don't take my answer to the bank.

don tascii

unread,
Oct 21, 2016, 7:08:54 PM10/21/16
to CommandBox
confirmed:  jvmArgs worked for me.  you just give it the same arguments as the java.exe command. (-cp or -classpath for setting classpath) : 

CommandBox:myv> server start JVMargs="-cp ."
Contacting ForgeBox to determine the best version match for [10].  Use an exact 'cfengine' version to skip this check.
WAR/zip archive already installed.
The server for C:\webroots\myv is starting on 127.0.0.1:50635... type 'server status' to see result
CommandBox:myv> server show
{
    "app":{
        "cfengine":"adobe@10"
    },
    "verbose":true,
    "JVM":{
        "args":"-cp ."
    }
}
CommandBox:myv> server status --verbose


myv (running)  127.0.0.1:50635 --> C:\webroots\myv


  Starting in background - Server is up - http-port:50635 stop-port:55952 PID:8256 version 3.4.10


  C:\Users\user\Downloads\commandbox-jre-win32-3.3.0\jre\bin\java.exe
    -cp .
    -Xmx512m
    -Xms512m
    -jar "C:\Users\user\.CommandBox\lib\runwar-3.4.10.jar"
    --background=true
    --port 50635
    --host 127.0.0.1
    --debug=false
    --stop-port 55952
    --processname "myv  [adobe 10.0.21+300068]"
    --log-dir "C:\Users\user\.CommandBox/server/F072138B9E86DC43FD4DC1C70F3B5CAF-myv/adobe-10.0.21.300068/logs"
    --open-browser true
    --open-url http://127.0.0.1:50635
    --cfengine-name "adobe"
    --server-name "myv"
    --tray-icon "C:\Users\user\.CommandBox\cfml\system\config\server-icons\trayicon-cf10-32px.png"
    --tray-config "C:\Users\user\.CommandBox/server/F072138B9E86DC43FD4DC1C70F3B5CAF-myv/adobe-10.0.21.300068/trayOptions.json"
    --directoryindex "true"
    --cfml-web-config "C:\Users\user\.CommandBox/server/F072138B9E86DC43FD4DC1C70F3B5CAF-myv"
    --cfml-server-config "C:\Users\user\.CommandBox/engine/cfml/server/"
    --timeout 240
    -war "C:\webroots\myv"
    --lib-dirs "C:\Users\user\.CommandBox/server/F072138B9E86DC43FD4DC1C70F3B5CAF-myv/adobe-10.0.21.300068/WEB-INF/lib"
    --web-xml-path "C:\Users\user\.CommandBox/server/F072138B9E86DC43FD4DC1C70F3B5CAF-myv/adobe-10.0.21.300068/WEB-INF/web.xml"
    --urlrewrite-enable false


CommandBox:myv>

br...@bradwood.com

unread,
Oct 21, 2016, 7:30:39 PM10/21/16
to comma...@ortussolutions.com
Yes, use the libDirs parameter to the start command (or the corresponding server.json setting).  This is a comma-delimited list of paths to folders that contain jars you wish to be class loaded into the application.  

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

E-mail: br...@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com 
 
 
--------- Original Message ---------
--
You received this message because you are subscribed to the Google Groups "CommandBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commandbox+...@ortussolutions.com.
To post to this group, send email to comma...@ortussolutions.com.
Visit this group at https://groups.google.com/a/ortussolutions.com/group/commandbox/.
To view this discussion on the web visit https://groups.google.com/a/ortussolutions.com/d/msgid/commandbox/b00300da-a82e-4a31-add5-e37b2504ea82%40ortussolutions.com.
For more options, visit https://groups.google.com/a/ortussolutions.com/d/optout.

br...@bradwood.com

unread,
Oct 21, 2016, 7:46:05 PM10/21/16
to comma...@ortussolutions.com
While setting the class path will work, it's a bit hacky.  Just use the libDirs parameter as it's intended for this purpose.

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

E-mail: br...@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com 
 
 
--------- Original Message ---------
--
You received this message because you are subscribed to the Google Groups "CommandBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commandbox+...@ortussolutions.com.
To post to this group, send email to comma...@ortussolutions.com.
Visit this group at https://groups.google.com/a/ortussolutions.com/group/commandbox/.

Dave Merrill

unread,
Oct 23, 2016, 8:01:57 PM10/23/16
to comma...@ortussolutions.com
Thanks guys. Neither of those methods involve JavaLoader, right? JavaLoader is a great tool for dynamic loading, but I've already been told it has problems with the specific jars we need to load.

--------- Original Message ---------
To unsubscribe from this group and stop receiving emails from it, send an email to commandbox+unsubscribe@ortussolutions.com.

--
You received this message because you are subscribed to the Google Groups "CommandBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commandbox+unsubscribe@ortussolutions.com.

To post to this group, send email to comma...@ortussolutions.com.
Visit this group at https://groups.google.com/a/ortussolutions.com/group/commandbox/.

don tascii

unread,
Oct 23, 2016, 9:40:55 PM10/23/16
to CommandBox
On Sunday, October 23, 2016 at 6:01:57 PM UTC-6, Dave Merrill wrote:
> Thanks guys. Neither of those methods involve JavaLoader, right?

No. Commandbox does not use javaLoader. It relies on runWar's class loader, which is java.net.URLClassLoader

dmer...@paperthin.com

unread,
Nov 13, 2017, 11:55:20 AM11/13/17
to CommandBox
Hi folks, taking a look at this again after a long while.

First off, just to confirm my understanding, the server.json file at the root of the server instance is used by default, yes?

Second, to add a directory to the classpath, my understanding is that it should include something like this::
        "libDirs":"\\path\\to\\my\\jars\\"
Is that right? Does it go at the root of server.json?
And the paths listed should relative to the server root?

Third, is it possible to add mappings via server.json? (Adding them through Application.cfc isn't possible for reasons not worth going into here.)

Thanks again for any assistance,
Dave


On Friday, October 21, 2016 at 7:46:05 PM UTC-4, Brad Wood wrote:
While setting the class path will work, it's a bit hacky.  Just use the libDirs parameter as it's intended for this purpose.

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

br...@bradwood.com

unread,
Nov 13, 2017, 6:03:46 PM11/13/17
to comma...@ortussolutions.com
> First off, just to confirm my understanding, the server.json file at the root of the server instance is used by default, yes?
 
 
> Second, to add a directory to the classpath, my understanding is that it should include something like this::
        "libDirs":"\\path\\to\\my\\jars\\"
 
Sort of.  You are correct that backslashes need to be escaped, but a path like that looks like a *nix path, which would use forward slashes.  A path starting with a slash is assumed to be absolute so the path you have above on Windows would resolve to the root whatever drive letter was on your current working directory.  Perhaps that's what you wanted, but I assume not.  
 
> Does it go at the root of server.json?
 
Pro tip: use the CLI to set these with the "server set" command.  Hitting tab will show you all the possible options.
 
> And the paths listed should relative to the server root?
 
It depends.  An absolute path is, well absolute! A relative path passed to a CLI param will be relative to the current working dir.  a Relative path in a server.json will be relative to the directory that the JSON file lives in.  (Note, server.json doesn't be in the web root).  A global server default config setting will be relative to the web root.  So in your case, the answer would be yes if your server.json is in the web root.
 
> Third, is it possible to add mappings via server.json?
 
No, but not to worry, we have another project that manages that and more called CFConfig.
 
 
That project will not only allow you to list/add/edit/delete CF mappings from the command line, you can package a .cfconfig.json file that has your CF mappings in it along with datasources, mail servers, timeouts and anything else that can be set in the CF administrator.  
 

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

 
 
--------- Original Message ---------
Reply all
Reply to author
Forward
0 new messages