0

I have an old project in RAD 7.5 that is built as a JAR to be used as a library in other projects. I'm trying to convert it to be built with Maven (part of a larger effort to move most projects to Maven) and I'm stuck on the classpath. The pom.xml looks liket his:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <name>My Framework Jar</name>
    <groupId>com.mycompany</groupId>
    <artifactId>MyFramework</artifactId>
    <version>1.0.1</version>
    <packaging>jar</packaging>
    <build>
            <!-- can't change the directory structure to how Maven likes it so specify the source directory -->
        <sourceDirectory>src/com/mycompany</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <groupId>org.apache.maven.plugins</groupId>
                <version>2.1</version>
                <configuration>

                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <!-- This will add project version into manifest file-->
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
        <finalName>MyFramework</finalName>
    </build>
</project>

The problem is that when I try to produce a jar, I get tonnes of "cannot find symbol" errors that reference class names in the jar files that this project is dependent on. There's already a .classpath file that seems to be what RAD uses for building the project - is there a way to get Maven to read this file so it knows what jars are needed?

Betlista
  • 10,327
  • 13
  • 69
  • 110
FrustratedWithFormsDesigner
  • 26,726
  • 31
  • 139
  • 202

1 Answers1

0

Since Maven manages the dependencies in the repository on your machine and uses them to compile and run your project those libraries are no longer directly in your project. So you might have to change your .classpath to point to your repo (~/.m2). When I use Maven Eclipse has a nice plugin that allows you to convert the project to a Maven project. This plugin allows the classpaths to be managed in the pom.

Bob Paulin
  • 1,088
  • 8
  • 13
  • I think the problem is that Maven doesn't seem to be reading the existing .classpath file. I think if it did, then it would know how to find the dependencies that it thinks are missing. – FrustratedWithFormsDesigner Dec 21 '12 at 14:22
  • Right and I don't think Maven actually reads those files. .classpath gets generated by Eclipse for it's own purposes. I think the only file Maven reads is the pom.xml – Bob Paulin Dec 21 '12 at 14:27
  • Really? Well in that case I need to make Maven aware of the local jar files that are already listed in the .classpath file. How can I tell Maven to use specific jar files? I tried using but Maven is trying to download the jars from somewhere. Not what I want since the jars are already present in the workspace. – FrustratedWithFormsDesigner Dec 21 '12 at 14:40
  • Right so the "Maven" way to do this is by installing those artifacts into your repo http://maven.apache.org/plugins/maven-install-plugin/examples/specific-local-repo.html And then pulling them in as dependencies. Maven is so convention driven trying to find a way around this may be quite painful. – Bob Paulin Dec 21 '12 at 15:08
  • @Bop Paulin: Is it possible to do this without setting up repositories? Most of the jars are compiled from other projects here. I just wanted a simple way to include pre-existing jars... – FrustratedWithFormsDesigner Dec 21 '12 at 15:09
  • If your company is sold on Maven you may want to look into building out an enterprise maven repo like Artifactory or Nexus. This way you have a place to install things to so other people can get them with out manually installing them locally. – Bob Paulin Dec 21 '12 at 15:10
  • Found this http://stackoverflow.com/questions/364114/can-i-add-jars-to-maven-2-build-classpath-without-installing-them#364188 But I can't say I've tried it. Or recommend doing it that way. – Bob Paulin Dec 21 '12 at 15:12
  • @Bop Paulin: Yes, I've found that and tried it but it doesn't seem to work. Maven keeps telling me to download the file manually from the project website. – FrustratedWithFormsDesigner Dec 21 '12 at 15:18