2

i have written a java project with eclipse. Now i want to manage it under maven. The method to transplant is i create a new maven project with m2eclipse, and copy all java and used jar to the according dir, which means i put the java files into src/main/java, and put jar files to src/main/resource.

The problem is: When i build this project with maven, the manifest file in result jar include No classpath info.

i have found that i can use the local maven repo, but i don't think this is a good solution for me.

i want to use the jars in the src/main/resource dir, and i want to write the jar names into the manifest file.

how can i do it???

CodeBoy
  • 591
  • 6
  • 12
  • "write the jar names into the manifest file" means put the jar names to the classpath in manifiest file.. – CodeBoy Apr 19 '12 at 09:14
  • 1
    It seems you don't really get what Maven actually is about. Dependency management is one of its most valuable features. What you're trying to do is against Maven philosophy. It smells like Ant. – Michał Kalinowski Apr 19 '12 at 09:21

1 Answers1

3

First of all, if you want to convert an existing project to Maven, there's a wizard to do that m2eclipse, which allows you to do that. In m2e for Eclipse Indigo, it can be found under Maven > Enable Maven Nature.

To add classpath info to the Manifest, you can use the maven-jar-plugin configuration like this:

  <plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
      <archive>
        <manifest>
          <addClasspath>true</addClasspath>
          <classpathPrefix>lib</classpathPrefix>
        </manifest>
      </archive>
    </configuration>
  </plugin>

This will add the classpath entries to the manifest and will reference each jar file from a directory called lib.

In your runtime environment, you just have to make sure that the lib directory is there (next to the executable jar file) and contains the required libraries. If you want to automate this, you can use the Maven Assembly Plugin: http://maven.apache.org/plugins/maven-assembly-plugin/

nwinkler
  • 52,665
  • 21
  • 154
  • 168
  • BTW: This looks like an almost identical question, which also has an example of the assembly configuration in one of the answers: http://stackoverflow.com/questions/10224631/how-do-you-create-a-standalone-application-with-dependencies-intact-using-maven – nwinkler Apr 19 '12 at 09:30