开发者

How to add a jar build by a project to the project in eclipse?

I have a project which as part of the build process creates an XMLBeans jar file (stbSchemas.jar) which I want to include and reference in this project.

Is this the best way to go about this (Single project) or should I have a child project which is built from the parent project?

I am building this using Maven2 inside Eclipse. Is there a better way to do this so 开发者_JAVA百科that I can maintain the integrity of the projects and stability of the builds.


Hmm. If I understand correctly, you're saying that the you need to reference the stbSchemas.jar in your project in order to build some code that DOESN'T go into the stbSchemas.jar file. If that's a correct assumption, then I think you should probably do a little bit of refactoring so that you have something like this:

1) a Maven parent pom file at the top level of the project. That parent pom has a modules section that would reference the 2 modules from step 2. E.G:

<modules>
  <module>stbSchemas</module>
  <module>core</module>
</modules>

2) Split the code into clean modules. stbSchemas would be the first, your other code would be a 2nd module. Each of those modules gets its own pom.xml file that would reference the parent pom file like this:

<parent>
       <groupId>parent.group</groupId>
        <artifactId>parent</artifactId>
        <version>1.0-SNAPSHOT</version>
      </parent>

The second module's pom.xml file would also need a dependency section for stbSchemas.jar, like this:

<dependency>
  <groupId>my.group</groupId>
  <artifactId>stbSchemas</artifactId>
  <version>1.0-SNAPSHOT</version>
</dependency>

Then, when you build your second module, it'll pick up stbSchemas.jar.

3) Once you've got that (or something similar) setup in Maven, you can use the maven eclipse plugin (mvn eclipse:eclipse) to generate a correct eclipse classpath for the whole project. You can then refresh the project in Eclipse, and that will put stbSchemas.jar on the classpath for you.


My suggestion is that, when you build the jar using Maven, lets have one folder say "runtime" in the project where you want to use this jar. And through maven only copy the jar to runtime of the project as soon as the jar is created so whenever you will have a new build, you will have the latest jar in the runtime folder. And now make your project to refer to the jar from the runtime folder. by adding it in its build path. Hope this helps


write a script to copy the jar to the desired folder and edit the xml file in .settings folder of the project to include the jar as a reference through the same script or add it in its buildpath at runtime.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜