Issue 423 in flyway: Classpath issue with EAR and Websphere

92 views
Skip to first unread message

fly...@googlecode.com

unread,
Jan 28, 2013, 2:57:17 PM1/28/13
to flywa...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 423 by marcin.j...@gmail.com: Classpath issue with EAR and
Websphere
http://code.google.com/p/flyway/issues/detail?id=423

Hi, I'm trying to use flyway in a multi-module project:

my-project
\-ejb
\-war
\-ear

I've added migration code in ejb module in @Startup and @Singleton bean in
@PostConstruct method. Ive put migrations to
/src/main/resources/db/migrations in ejb module, but they cannot be found.

I think its classpath issue - ClassPathScanner.getClassLoader returns EAR's
classloader but I need ejb's module classloader.

Is there other solution than modifying code and passing right classLoader
to ClassPathScanner ? Like that :

Flyway f = new Flyway();
f.setClassLoader(this.getClassLoader());
f.migrate();

I use Websphere 8.5.0.1 with JEE6.

Thanks!

fly...@googlecode.com

unread,
Jan 29, 2013, 4:55:25 AM1/29/13
to flywa...@googlegroups.com
Updates:
Status: Accepted
Labels: Component-Core

Comment #1 on issue 423 by axel.fontai...@gmail.com: Classpath
Hi Marcin,

thanks for reporting this! Adding a setClassLoader method is something I
think will be useful beyond just your case (WS 8.5/EAR/EJB).

Pull request welcome.

Cheers
Axel

fly...@googlecode.com

unread,
Jan 29, 2013, 8:22:25 AM1/29/13
to flywa...@googlegroups.com

Comment #2 on issue 423 by marcin.j...@gmail.com: Classpath issue with EAR
and Websphere
http://code.google.com/p/flyway/issues/detail?id=423

Thanks for reply.

Found out that case is different - ClassLoader.getResources() doesnt work.
When I point exactly to sql script - class loader finds it.

fly...@googlecode.com

unread,
Jan 29, 2013, 12:29:58 PM1/29/13
to flywa...@googlegroups.com

Comment #3 on issue 423 by axel.fontai...@gmail.com: Classpath
OK, thanks for the info. What's the output of ClassLoader.getResources()?
Simply null?

Is there another way to load resources in WebSphere?

Could you post a debug output? Maybe it includes some clues.

Cheers
Axel

fly...@googlecode.com

unread,
Feb 1, 2013, 4:17:20 AM2/1/13
to flywa...@googlegroups.com

Comment #4 on issue 423 by marcin.j...@gmail.com: Classpath issue with EAR
and Websphere
http://code.google.com/p/flyway/issues/detail?id=423

Empty.

Yeah, there's one way - you need to know resources names...

Same issue is described here (getResources) :
http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/impl/WebSpherePackageScanClassResolver.html

getClass().getClassLoader().getResources("db/migration") - EMPTY
getClass().getClassLoader().getResources("db/migration/V1__Base_schema.sql")
-
returns URL with that file.

Do you have idea how it could be handled by flyway ? Im interested in
preparing pull request for this.

fly...@googlecode.com

unread,
Feb 1, 2013, 5:58:24 AM2/1/13
to flywa...@googlegroups.com

Comment #5 on issue 423 by axel.fontai...@gmail.com: Classpath
This is tricky as the filename is not known in advance.

Once any resource within the location is retrieved, all lights are green,
as we then have a path on disk from which we can work our way down.

I believe Spring gets around this by accepting a class object from the same
physical folder on disk, and calculates the relative path from there. No
idea yet on how to implement this cleanly in Flyway or if there is a better
way.

Cheers
Axel



fly...@googlecode.com

unread,
Feb 4, 2013, 4:31:07 AM2/4/13
to flywa...@googlegroups.com

Comment #6 on issue 423 by marcin.j...@gmail.com: Classpath issue with EAR
and Websphere
http://code.google.com/p/flyway/issues/detail?id=423

OK. I didnt find any better solution either.
I made quick changes which are working for me - available in my fork :

https://github.com/mjancewicz/flyway

ClassPathScanner is configurable from Flyway class. I also added scanner
for Websphere. Disadvantage of this solution is db/migration must be places
in same jar in which class is running migration. Sample usage :

Flyway flyway = new Flyway();
flyway.setClassPathScanner(new WebsphereClassPathScanner(getClass()));

fly...@googlecode.com

unread,
Feb 4, 2013, 5:15:48 AM2/4/13
to flywa...@googlegroups.com

Comment #7 on issue 423 by axel.fontai...@gmail.com: Classpath
Hi Marcin,

I've put some more thought into this and I believe this could be a
minimally invasive solution:

For WebSphere, require the presence of an empty file named flyway.location
in each location. We can then get the path on disk for the file, and start
scanning from there.

This is minimally invasive for Flyway (no additional config,
WebSphereClassPathScanner automatically used behind the scenes if ibm
classloader is detected) and for the user (one additional file, explained
in the docs, detailed exception message if missing)

What do you think? Would this work? Do you see any issues?

Cheers
Axel

fly...@googlecode.com

unread,
Feb 4, 2013, 6:05:01 AM2/4/13
to flywa...@googlegroups.com

Comment #8 on issue 423 by marcin.j...@gmail.com: Classpath issue with EAR
and Websphere
http://code.google.com/p/flyway/issues/detail?id=423

It should work. I will check it in next few days.

fly...@googlecode.com

unread,
Feb 5, 2013, 5:34:18 AM2/5/13
to flywa...@googlegroups.com

Comment #9 on issue 423 by marcin.j...@gmail.com: Classpath issue with EAR
and Websphere
http://code.google.com/p/flyway/issues/detail?id=423

It works. You can check it out in my fork I posted above.

fly...@googlecode.com

unread,
Feb 11, 2013, 8:22:57 AM2/11/13
to flywa...@googlegroups.com

Comment #10 on issue 423 by axel.fontai...@gmail.com: Classpath
Hi Marcin,

I've committed some untested code (I have no access to WebSphere). Could
you give it a shot and let me know if it works for you?

Thanks
Axel

fly...@googlecode.com

unread,
Feb 11, 2013, 9:03:02 AM2/11/13
to flywa...@googlegroups.com

Comment #11 on issue 423 by marcin.j...@gmail.com: Classpath issue with EAR
and Websphere
http://code.google.com/p/flyway/issues/detail?id=423

Yes, it works like a charm :-)
Thanks!

fly...@googlecode.com

unread,
Feb 11, 2013, 10:11:42 AM2/11/13
to flywa...@googlegroups.com
Updates:
Status: Fixed

Comment #12 on issue 423 by axel.fontai...@gmail.com: Classpath
Hi Marcin,

Thanks again for your contribution. It was an important help to get this to
work. I've credited you in the hall of fame:
http://flywaydb.org/contribute/hallOfFame.html

Cheers
Axel

fly...@googlecode.com

unread,
Feb 13, 2013, 7:36:18 AM2/13/13
to flywa...@googlegroups.com

Comment #13 on issue 423 by hirsch.m...@gmail.com: Classpath issue with EAR
and Websphere
http://code.google.com/p/flyway/issues/detail?id=423

Is there a release planned containing this issue in the near future? Would
like to have it in a release :)

Cheers,
Michael

fly...@googlecode.com

unread,
Oct 1, 2014, 12:44:31 PM10/1/14
to flywa...@googlegroups.com

Comment #14 on issue 423 by owenly...@gmail.com: Classpath issue with EAR
and Websphere
https://code.google.com/p/flyway/issues/detail?id=423

Has this been added to a stable release?

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
Reply all
Reply to author
Forward
0 new messages