简体   繁体   中英

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 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. EG:

<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

编写脚本以将jar复制到所需的文件夹,并在项目的.settings文件夹中编辑xml文件,以通过相同的脚本将jar包含为参考,或在运行时将其添加到其buildpath中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM