2

I guess I haven't really had to do this much before because I am running into a strange issue. I am trying to generate a JAR from an existing Java project and then and putting it into a Spring Maven project. I'm sure I'm including it correctly, I have done this many times before with 3rd party JARs that I get (even though its a Maven project I have included some obscure JARs in it and put on buildpath, etc), with my JAR within Eclipse it is showing up fine as if its included, I have a test class that is importing a class from the JAR, instantiating it, etc and its not showing any errors (imports are fine in the IDE, etc), however when I go to do a Maven install I get:

[ERROR] /media/src/main/java/org/jadefalcon/automation/DataSetup/test.java:[11,15] package org.test does not exist
[ERROR] /media/src/main/java/org/jadefalcon/automation/DataSetup/test.java:[21,2] cannot find symbol

I have tried doing a Maven clean but still the same problem, the JAR class I am testing with is this: (was trying a more complex one but then tried this to troubleshoot the issue)

package org.test;

public class something {

    public String main () {
        return "it is definitely working fine";
    }

}

Here is the JAR I generated (with sources visible): https://docs.google.com/leaf?id=0BzB_xvrbRpbYODQyMjEzOWEtOTdjNS00YjM3LTlkZGUtNjY5NmIwN2RiNTRj&hl=en

I would appreciate any advice as I am rather perplexed and frustrated by this. Thanks

abalogh
  • 8,239
  • 2
  • 34
  • 49
Rick
  • 16,612
  • 34
  • 110
  • 163

2 Answers2

2
  • You can include a 'regular' jar in your maven project -just as you described- though it's not a best practice mainly because then you not even lose the functionality of Maven for that jar, but also the whole point of Maven dependency management: you will have to include that jar with your source to make it build.

  • You can of course also create a Maven artifact for that jar, build it with Maven, install it with Maven and use it as a normal Maven dependency.

  • You also can create a parent .pom and have your dependency project as a module in it and also your real application (or also your real app can be your parent). See further here.

abalogh
  • 8,239
  • 2
  • 34
  • 49
  • yes I understand but its just a simple JAR that is done by another dev within our organization and the way we do our deployment its not much of a hassle to make sure its always included, just seems easier than setting up a repository, etc, especially since we would have to restrict access as well – Rick May 20 '11 at 19:09
1

Since this caused me quite a bit of grief, I figure I should post the solution I found. Apparently you aren't supposed to just include a regular lib JAR in a maven project (although I swear I have done it before and it worked), I found this way to include a local JAR that isn't form a repository from this post:

Can I add jars to maven 2 build classpath without installing them?

I did this and its doing the maven install properly (where version and artifactID are just made up value)

        <dependency>
    <groupId>org.test</groupId>
    <artifactId>test</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/testjar.jar</systemPath>
</dependency>
Community
  • 1
  • 1
Rick
  • 16,612
  • 34
  • 110
  • 163
  • *Apparently you aren't supposed to just include a regular lib JAR in a maven project*. **Exactly!** – Sean Patrick Floyd May 20 '11 at 07:16
  • Not that I agree with that though, its pointless to have to setup a repo for an internally maintained jar given that you also have to setup security, etc for that (when its something that people outside the company aren't supposed to have access to), what a waste of time.. the way I said above works and I'll leave it at that – Rick Jun 09 '11 at 21:35