Maven, cyclic imports, classpath for compile -


i have task migrate legacy project ant maven , have trouble cyclic imports. problem ant builds many jars contains same classes.

originally ant project have 1 src folder , contains packages there. maven compatibility me require split src folder several modules pom.xml (as says in guides , manuals).

fast example.

foo.java package myapp; import my.domain.myapp.bar; ...  bar.java import my.domain.myapp.foo; ...  src/my/domain/myapp/foo/foo.java (foo.jar) src/my/domain/myapp/bar/bar.java (bar.jar) 

there 2 packages placed in same parent package , no problems compilation. ant project compile java classes , generate artifacts patterns. so, compiled *.class copying jar. maven did't see same way, suppose me need split packages like:

pom.xml (parent) --foo ----src/main/java/my/domain/myapp/foo/foo.java ----pom.xml --bar ----src/main/java/my/domain/myapp/bar/bar.java ----pom.xml 

so, in maven know set dependency jar jar. in case i've cyclic imports locks build. can't build foo.jar without bar.jar , vice versa.

maven have specify class path variable compilation process instead set dependency jar? workaround?

best practice welcome.

one thing need aware of when using maven is, maven required components of project (jars, wars, or other kind of modules) defined. clear, non-cyclic dependency 1 of prerequisites.

if faced problem because of cyclic dependency, there need into: (answer of @matsev provides quite ways , adding )

  1. are foo , bar appropriate split separate module, if need closely coupled?
  2. if think should put separate module, need refactor code. there lots of different ways solve problem, depending on actual situation:
    • introduce interfaces foo , bar using corresponding interface, , can put interfaces separate modules (call foo-api or bar-api)
    • double dispatching
    • any other patterns design foo , bar give clear relationships between foo , bar. no 1 can tell depends on need. 1 thing clear: there area improvement design. giving big bad smell now.

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -