Dependency on 3party jars at runtime (run and start)

138 views
Skip to first unread message

Frank Døssing

unread,
Jun 12, 2015, 7:20:50 AM6/12/15
to play-fr...@googlegroups.com
Hi All,

coming from .NET I'm into a bit of a puzzle. Hoping for some help.

I'm on Play version 2.0.8 and have this challenge that my Play application(Y) is dependent on another JAR (application(X) I have created). The JAR of X  is located in the \lib folder. Application X is using some JAR's from an external API located on the server (the location can be different locations). These JAR's have references to other JARS, so in total there are references to 370 JAR's.

My challenge is now that I need a way in my play application (Y) to be able to, at runtime (dev, test and prod) to be able to reference the JAR hierarchy of application X. 

But can I use the PLAY_OPTS or JAVA_OPTS environment variable to set the classpath? And if yes, how can I ensure that JAR's in the classpath also include the referenced other JAR's?

Or is there a better way to accomplish this?

Right now when calling a method that invokes a call to application X, I get this error:

"play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[NoClassDefFoundError:"

At the same time I can see that when I add one of the 3 JAR's using STS, the references JAR from that are included in the classpath.

Appreciate any help or push in a direction.

Cheers
Frank

Daniel Manchester

unread,
Jun 12, 2015, 12:08:40 PM6/12/15
to play-fr...@googlegroups.com
Hi,

This situation sounds like a great case for "managed dependencies."

With managed dependencies in the Java/Scala ecosystem, the de facto standard (which originated with Apache Maven) is for a library to publish a POM/pom.xml (or, less commonly, an ivy.xml). The POM specifies the library's dependencies.

For an example, take a look at the POM of Apache Commons Lang; in particular, its <dependencies> element.

Consumers of a library (applications, or other libraries) process its POM, obtain the dependencies' JARs and their pom.xml's, process those pom.xml's, etc., until the consumer has accumulated all needed JARs.

I'm not sure what build tool/IDE you're using, but I'd focus on getting it to produce a usable POM when you build library X. As I imagine many of the 370 JARs are third-party ones that publish their own POMs, library X's POM shouldn't need to list anything approaching 370 dependencies. Rather, X's POM should really only need to list libraries it uses directly, and their POMs should take care of the rest.

Once X's POM is in shape, your application Y would declare a dependency on X in the application's build.sbt.

Dan

Frank Døssing

unread,
Jun 15, 2015, 7:21:01 AM6/15/15
to play-fr...@googlegroups.com
Hi Dan,

thanks for your reply. I see the benefit of using Maven - but I still can't see I can solve my challenge, and I'm pretty confused.

I'm looking for a way to include the 3party JAR's as reference so I at runtime can configure where the 3 JAR's are located and load the needed dependencies.

So far I have done this: in System X project I have added the JAR's through STS Spring (IDE) by using Properties -> Java Build Path -> Add External JAR's. Following I can see the referenced JAR's (370 pieces) in the "Referenced Libraries". This works. I can also see when exporting System X to a JAR that the classpath includes a reference to the initial 3 JARs (ClassPathEntry). But I'm pretty lost on how to add the 3 JAR's to a Maven project the same way?. So actually it's a question of how to let my project know, at runtime, where the JAR's used by System X is located (I guess).

Does this make any sense?

The final solution should be deployed to X number of servers where the JAR's I need to include as Reference can be located on different locations. On my DEV server the JAR's are located in E:\oracle\middleware\system\lib - on a production server this could be F:\oracle\middleware\system\lib or maybe even /u01/app/Oracle/Middleware/System/lib or somewhere else. 


Cheers
Frank

Dominik Dorn

unread,
Jun 15, 2015, 7:30:01 AM6/15/15
to play-framework
Frank,

instead of adding the dependencies using STS, add them through defining them in your build.sbt file. This way, they get included in the pacakge you will deploy on your servers and you don't have to worry on what to include or where the jar files are etc. 

When you want to deploy, use sbt dist or activator dist to create a file/package you can deploy on your server. 



--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/88fe9768-ba33-422b-9459-210ac158eba1%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Dominik Dorn
http://dominikdorn.com
http://twitter.com/domdorn

Skripten, Mitschriften, Lernunterlagen, etc. findest Du auf http://www.studyguru.eu !

Frank Døssing

unread,
Jun 15, 2015, 7:49:43 AM6/15/15
to play-framework
Hi Dominik,

thanks - but my application depends on talking to a pre-installed system(AA) on a server, using the system's API, which is exposed through Java JAR's. So one could argue that I'm actually dependent on a complete running system. Hence I would  guess that the best way is still to have a reference to the JAR's, but at runtime point to the "real" JAR's - also to be sure that things are aligned, so if a patch have been applied on a specific server on system AA it does not break anything.

If I add JAR's using the build.sts I would have to include all JAR's needed (370) in my build, yes?

Can't I add a the reference to the JAR's to the classpath when execute the "run" or "start" command? I can compile my project with no problem. First when I run the application and execute I get the "NoClassDefFoundError".

/Frank

You received this message because you are subscribed to a topic in the Google Groups "play-framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/play-framework/HcpA3N37TbA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/CABHM76VL7Qoat9jbppnzn_mq8qVwNWeWOzPXLfNjC%2BaQf%2BMDsA%40mail.gmail.com.

Dominik Dorn

unread,
Jun 15, 2015, 8:12:08 AM6/15/15
to play-framework
you can also just put them in the projectDirectory/lib folder. 


For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages