I have probably maximized my inquries today LOL. ...
# box-products
r
I have probably maximized my inquries today LOL. HOWEVER! I have yet another question regarding custom jars, I am not a java person, so I apologize. I was reading this: https://commandbox.ortusbooks.com/release-history/5.x-versions/whats-new-in-5.3.1#recursive-jar-scanning-libdirs The reason I pondered on this is after using
server forget
to delete some servers, I forgot that there were jars that I needed to put back after creating the new server. Then I thought how it would be nice to be able to delete a server and spin up a new server at whim without having to manually add jar files back into the lib folder within Lucee. I read this and used
server set app.libDirs=lib
I verified it is within the server.json. Also, I confirmed the jars are in the new custom lib folder. I restarted the server, but the website errors because it cannot find the jar file. I moved the lib folder around to see what, if any, different errors may occur and it does throw an error in commandbox when it cannot find the lib folder, so I am pretty sure that the lib folder is getting recognized during the spin up. The following is the line that errors:
<cfset flyway = createObject("java", "org.flywaydb.core.Flyway").init()>
Maybe I cannot do this or this is not pointed in the cfset correctly now that the flyway jar is in a custom lib?
t
the libDirs is an absolute path or relative to server.json so
server set app.libDirs=lib
implies that lib is in the same directory as server.json
r
right, and it is in the same directory
t
ok so a quick look at the java docs Flymay does not have an empty constructor you will need something like
Copy code
flyway = createObject("java", "org.flywaydb.core.Flyway").configure().dataSource(url, user, password).load();
r
hmm, reading this doc again, it says that CommandBox used to only load jar files found in the root. Is that the root of where server.json lives or the web root?
my web root is a subdirectory from where server.json is currently located
i placed the lib folder in the parent directory of where the web root resides as I didn't want jar files in the web directory at all.
b
@ryan Do a
--trace --console
start and you'll see a list of every jar that CommandBox class loads from your lib dirs šŸ™‚
r
ok
thanks
b
CommandBox doesn't have any folder it loads jars from automatically. You have to tell it
So if you have
lib
then that's going to be a path relative to the location of the
server.json
file
So if you've moved the lib folder somewhere else, you need to point do it
ā€¢ ../lib ā€¢ relative/path/to/lib ā€¢ C:/absolge/path/to/lib ā€¢ etc
As to the wording in your docs link above
When you configure libDirs for a server, CommandBox used to only load jar files found in the root. Now it will include sub directories which gives you more flexibility around how to install your jars.
notice it says "_*used to* only load jar files found in the root_". key word "used to". Meaning, now it is different.
The next sentence goes on to say "_*Now* it will include sub directories_". Key word, "Now", meaning as of version of 5.3.1
r
right, you chimed in and I didn't finish LOL
what I wanted to mentioned is that it then mentions subdirectories, which still means that maybe this is based off of the webroot.
b
You are totally correct to not want to have to manually install the jars every time
That would be terrible šŸ™‚
IN fact, you shouldn't even need to comit those to your repo. Include them as an installation dependency in the
box.json
so
box install
pulls them in.
It's also worth noting
this.javaSettings
in your
Application.cfc
is also a valid way to load these. it's sort of 6 of one, half a dozen of the other.
mentions subdirectories
No, it just means sub directories of the folders you pointed it to
r
I need to refrain from using Application.cfc because it is in a repo that goes to production that will not have the lib directory. I like the box.json approach as it is essentially non-evasive to any repo files.
šŸ‘ 1
I did originally use
server set app.libDirs=lib
b
I solve that by hosting prod on CommandBox as well, but to each their own šŸ˜†
I did originally use
server set app.libDirs=lib
Which is fine, so long as your lib folder is in the same directory as the
server.json
r
I actually will need to read up on regarding commandbox and production, but we get a lot of clients that have various different setups, so we essentially leave it that way.
b
We use Docker for prod, but it's great for the env vars, cfconfig, server.json, etc to just be the same all the way across the board
r
right, i noticed the env vars
b
Generally speaking, using CommandBox on production is the same as using it on dev. Just ensure your
profile
is set to
production
so it's secure by default and set it up as a Windows service (which we have a module for)
r
very nice
I will look into that
thanks
b
We have clients doing this just with windows Vms because it's easier to deploy a new server than a typical CF install and manual setup
but I get that's a bit mental shift for a lot of clients, lol
r
yes, it is haha
I convert everything I do to using commandbox servers
b
The next version of CommandBox will support mod_cfml out of the box which will remove the last big blocker for people
r
it makes life so much easier for development
šŸ‘ 1
b
you'll finally be able to sit a single CommandBox instance behind Nginx/Apache/IIS to have it host multiple web roots
r
very nice
I set up a client last year that was a SaaS company. They had all sorts of clients, each with their own IIS web instance and they were struggling as developers with having to constantly keep up with what's on staging and production with files and they were not using Git, either.
I set them up with Git and got the devs running with commandbox and to be able to switch between all of their clients on the dev environments.
šŸ‘ 1
it wasn't easy as they had all sorts of caveats in the way when it came to how they handled files.
ok, so, sorry about the tangent. Regarding the lib, it is sitting where the server.json is located. I have confirmed in the console trace the following:
[TRACE] Runwar: lib: adding to classpath: F:\code\web\sites\test\lib\flyway-core-5.2.4.jar
t
did you see the comment above? you can not use .init() the class does not have an empty constructor
Copy code
flyway = createObject("java", "org.flywaydb.core.Flyway").configure().dataSource(url, user, password).load();
šŸ‘šŸ¼ 1
r
i overlooked that @thisOldDave. Checking
r
@thisOldDave This is interesting because it worked this way when I threw the jars into the Lucee lib folder previously
at least, I was receiving correct information back, but maybe that's because this code is still operable beyond this errored line. I noticed there are try/catch blocks around this entire thing as well, so maybe it is just that now that I removed the try/catch blocks, it's like ripping off the band-aid. Lol
This warning seems to coincide with what you are mentioning as well @thisOldDave Found this warning in the console trace
Copy code
[WARN ] org.flywaydb.core.Flyway: Direct configuration of the Flyway object has been deprecated and will be removed in Flyway 6.0. Use Flyway.configure() instead.
Sorry for the bit of delay on this one. I was able to get this working after realizing that there was actually a third jar needed what was preventing flyway from operating. I had to take the
com.mysql.cj-8.0.19.jar
, a dependency for the flyway jar, from '\lucee-server\bundles\' and pasted it into the custom lib folder. Everything works beautifully this way now! Thank you all for your help in this!
ā¤ļø 1
Now that I'm thinking about it, I noticed that there was documentation on being able to point to a remote jar. I wonder if pointing to a mysql jar would be a better/cooler option instead of copying/pasting the jar. Looks like pointing to a jar is only available using http, so I guess it is not possible to point to a local jar that exists within the Lucee server. hmm.. maybe another path in server.json for
app.libDirs
would work, but I think I would have to make it a hard path rather than a relative path since the jar is located in a completely different place. Well, it seems like it is 6 of one, half a dozen of another when either copying/pasting it to the custom lib folder with the other jars or hard pathing it in the server.json. It is probably better to copy/paste because at least it will work with portability compared to an hard path possibly breaking if the server moved elsewhere. Going to see if I can make this work if the mysql jar is available online and point it that way for fun.
I have added a box.json file into the root with the following to test and see how/if this will work. I restarted the server but the jar is not found. Do I need to do more in order for the box.json file to be recognized? I ran
$ init
in commandbox to create the box.json and then added the following to the box.json file.
Copy code
{...
	"dependencies":{
		"flyway-core-5.2.4":"jar:<https://search.maven.org/remotecontent?filepath=com/github/spt-oss/flyway-core/5.2.4.0/flyway-core-5.2.4.0.jar>"
	}
...}
b
@ryan Did you run
Copy code
box install
or just add the dependency
Starting a server has nothing to do with installing dependencies
r
got it
box install
never even crossed my mind to try Lol
trying now
b
Yep, or you could do it the other way around. Run
Copy code
install "jar:<https://search.maven.org/remotecontent?filepath=com/github/spt-oss/flyway-core/5.2.4.0/flyway-core-5.2.4.0.jar>"
and it will ā€¢ download/install the jar ā€¢ add it to the
box.json
for you
r
oh very nice
This is interesting, I ran
install
then
start
. I noticed that a folder is automatically created within the lib folder named
flyway-core-5.2.4.0
. However, the page errors because it cannot find the file in that auto-created subdirectory. Is there possibly a setting that forces the jar to be placed within the lib directory and not a subdirectory or maybe there is something else I didn't do, like maybe the only option is to manually move the jar file into the lib folder?
none-the-less, this is becoming very cool
b
I don't really know enough about your setup to know what you've got going on.
But if you've got your
app.libDirs
pointing at the
lib
folder in your
server.json
then it should be loaded
But I have no idea what you've got in place
r
that's exactly what I have in my server.json
b
Note, the
intsall
command just piuts the jar on disk. A CommandBox isn't going to load it unless you tell it to
Ok, so do a
--trace
start and see if the jar shows up as being loaded.
r
It has loaded the jar based on the
--trace
I noticed that an
installPaths
was inserted into box.json as
Copy code
"installPaths":{
        "flyway-core-5.2.4":"lib/flyway-core-5.2.4/"
    }
The jar is not able to be found and errors when starting the web application. Being that this is a Lucee server, do I possibly need to add a mapping to this install path in lucee's server admin?
b
No, CF Mappings have nothing at all to do with loading jars
Please show the full stack trace here
Changes are, the jar is loaded fine but missing a dependency
Just because you received an error of some kind, doesn't mean the jar isn't being loaded
r
I believe the file pulled from search.maven.org is not quite the same as the file that I have been using. The file name is essentially the same except that my maven's file is 5.2.4.0 and mine is named with 5.2.4. When I swap these files and place the file I know is good into the subdirectory, then everything works. The definition for the class does not exist in the jar that is pulled from the maven website.
Copy code
cannot load class through its string name, because no definition for the class with the specified name [org.flywaydb.core.Flyway] could be found caused by (java.lang.ClassNotFoundException:org.flywaydb.core.Flyway not found by lucee.core [48];java.lang.ClassNotFoundException:org.flywaydb.core.Flyway;)

The Error Occurred in
\htdocs\db_migrate.cfm: line 56 
55:
56: <cfset flyway = createObject("java", "org.flywaydb.core.Flyway").configure().dataSource(jdbcUrl, user, password, initSqls).load()>
57:
This indicates to me that everything is working in terms of Commandbox and all, it is just the file itself is not exactly the same as was expected.
Thank you for the help, @bdw429s