3

I need to store an artifact in Maven/Nexus but when it's pulled down it must not have a version number at the end.

Before you berate me, point your scowl at Oracle.

I have comm.jar (Oracle comm port driver). I've put this in my nexus server & it comes down as comm-1.0.jar. But the JAR contains the following code:

if(streamtokenizer.ttype == -3 
    && (i = streamtokenizer.sval.indexOf("comm.jar")) != -1)

It's hard coded to use its own name to know where to find the configuration file that goes with it. The jar is signed so I can't make changes to it.

So... how to I store a jar in Nexus and not have an extension number on it ?


This isn't the exact answer to my question but it does solve my problem.

I called my jar "comm.jar-1.0.2.jar" The code looks for 'comm.jar' in the file name so now it finds it! ok, so it a fudge and I'm lucky the internal code is just looking for indexOf. but it works!

Thanks to everyone for there advice on this!

Jeff

jeff porter
  • 6,560
  • 13
  • 65
  • 123
  • 3
    Consider my scowl firmly directed towards Oracle. That's awful coding! – Duncan Jones Nov 14 '12 at 11:48
  • 2
    I guess that the problem is at runtime. So it won't have to be stripped until deployed with your application, right? So the question is how do you package your application? That's relevant to know IMO. – maba Nov 14 '12 at 11:56

2 Answers2

4

This isn't a complete answer, more a collection of thoughts on how you might approach this.

I think you will need to declare your dependency with the version number present, to ensure Maven is happy to resolve the artifact and build it. So, the trick will be ensuring the aritfact is renamed before it is bundled in your finished product.

The Maven dependency:copy-dependencies goal has a stripVersion parameter that might come in useful. I suspect you can use this to rename the JAR correctly, perhaps as part of an assembly (ensuring the depedency is moved to a directory that is part of the classpath).

Such a plan may well break your development environment, however. Perhaps you can get around that by fudging a JAR file with the right name?

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
  • @maba Any thoughts on avoiding the development environment breaking? – Duncan Jones Nov 14 '12 at 12:10
  • That really depends on the use case. Hard to say without any further information. The `comm.jar` is nothing I have ever had to use. – maba Nov 14 '12 at 12:10
  • For development, you could use the system scope hack and check in the jar to your source control http://stackoverflow.com/a/364188/116509 (I know it's usually a terrible idea, but in this case, probably justified) – artbristol Nov 14 '12 at 12:52
1

If you want it to work with a war project then you can use the File Name Mapping to strip the version.

<build>
    <plugins>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <outputFileNameMapping>@{artifactId}@.@{extension}@</outputFileNameMapping>
            </configuration>
        </plugin>
    </plugins>
</build>

The dependent jars will as normal end up in WEB-INF/lib but now without the version.

But from your question it is hard to tell what your end product is, war, jar, zip, ...

maba
  • 47,113
  • 10
  • 108
  • 118