1

Project 1: a Java/Maven project

Project 2: a Scala/sbt project

Thing: generally, an immutable object instantiated in from 3rd party Java library. For example, ThingBuilder.foo("bar").build()

Question: How can I define Thing in only one place, and have it used both in Project 1 and 2? (So the parameters in ThingBuilder are guaranteed to be the same in both projects.)

  • Just to be clear. In your example there are two different executables from the two projects running in two different JVM's. You're not simply trying to reuse a class defined in one language in the other language. Right? – candied_orange Feb 11 '18 at 4:21
  • Exactly. Perhaps the best way is to make Project 3, having Project 3 jar as a dependency in both, with some wrapper object to produce Thing. I don't really know! And would I do it in Java or Scala :) – Pete Feb 11 '18 at 4:26
  • Er no, what I want to know is if you're trying to share runtime state between two running executables, one of which has created the Thing object with a certain state and the other did not but wants to use it in that state. Or if you just want to be able to define Thing with a java class in the java project but create it as an object in your scala project where you would give it state and not share that object with the java/maven project. – candied_orange Feb 11 '18 at 4:31
  • The second goal: define it in a single place, instantiate it in both projects, but the instantiated objects are not shared/an instantiated object is not shared. The two executables communicate through a messaging system, so it's important they work with the same definition of Thing, but they don't share an instance of it directly. – Pete Feb 11 '18 at 4:40
1

One way would be to create a library wrapping the creation of the immutable object, and have it's creation driven by a shared config file.

lightbend's config is useful for this because it's implemented in Java, despite being a lightbend project.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.