Aroldo Bettega
Aroldo Bettega

Reputation: 35

Exporting multiple projects as jars

How do I export multiple projects as individual jar files each, so as to have a 1:1 ratio of project to jar? I have thousands of projects, and exporting each of them one by one would take way too long, and exporting them all as one jar is also not ideal, because I run them individually via the cron scheduler.

Edit - What I need, to be specific, is exactly what I get from running "Export -> Runnable JAR" in Eclipse, having "Package required libraries into generated JAR", except to do it in a faster way. Maven is apparently good for this, but I'm having trouble getting it to work like I want.

Upvotes: 1

Views: 893

Answers (2)

Hiro2k
Hiro2k

Reputation: 5587

To get the maven to create a runable jar with all your dependencies try doing this:

<build>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.4</version>
    <configuration>
      <archive>
        <manifest>
          <addClasspath>true</addClasspath>
          <mainClass>com.whatever.YourMainClass</mainClass>
        </manifest>
      </archive>
    </configuration>
  </plugin>
  <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2.1</version>
    <configuration>
      <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
      </descriptorRefs>
      <archive>
        <manifest>
          <mainClass>com.whatever.YourMainClass</mainClass>
        </manifest>
      </archive>
    </configuration>
    <executions>
      <execution>
        <id>make-assembly</id> <!-- this is used for inheritance merges -->
        <phase>package</phase> <!-- bind to the packaging phase -->
        <goals>
          <goal>single</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
</plugins>
</build>

Upvotes: 1

Benoit
Benoit

Reputation: 1993

You can use Maven. Then you just have to run a command like mvn package in each project folders to generate the jar files. You can write a script to automate this process.

Upvotes: 2

Related Questions