8

I received some compiled classes that I need to add to a project.

One solution I can think of is creating a jar with these files and manually uploading it to the repository. Obviously this will work. But I wonder if there is a more elegant solution. May be I can put them somehow under the project structure? So the files will be checked-in to the source control and it will easier to maintain their versions, etc.

crowne
  • 8,456
  • 3
  • 35
  • 50
Tarlog
  • 10,024
  • 2
  • 43
  • 67
  • 1
    There's nothing elegant about distributing unpackaged compiled classes in the first place, I'm afraid. – Sean Patrick Floyd Feb 07 '11 at 08:41
  • As Boris has implied, storing binary class files in a source control repository is a bad idea. – crowne Feb 07 '11 at 08:42
  • 4
    @Sean: I agree, but this is the given situation, quite new to me I must admit, but currently there is nothing I can do about it. – Tarlog Feb 07 '11 at 12:34

2 Answers2

8

Here's my approach as per the comments on Boris' answer (after finding myself needing to use the same yesterday, but unable to find the link to the answer I'd used):

In your project directory, create a folder called repo, which we'll use as a folder based Maven repository.

Add the following file repository to your project pom.xml:

<repositories>
    <repository>
        <id>file.repo</id>
        <url>file://${project.basedir}/repo</url>
    </repository>
</repositories>

Package your classes as a jar, and deploy them to the file repository, with the following command:

mvn deploy:deploy-file
-Durl=file:///absolute/path/to/your-project/repo \
-DrepositoryId=file.repo \
-Dfile=path-to-your.jar \
-DgroupId=some.external.project.group \
-DartifactId=the-artifact-name \
-Dversion=1.0 \
-Dpackaging=jar;

Following this you can just add a normal dependency on the jar in your project pom.xml, using the values for groupId, artifactId and version you passed above. You can then add the repo folder to SVN, and commit the changes to your pom.xml. Any developer checking out your project will now be able to use the same dependency without any effort.

Tim
  • 19,793
  • 8
  • 70
  • 95
2

The first idea is way better then checking in binaries that you don't have control over. So, bundle binaries in a jar, version it and deploy it on the repository.

Boris Pavlović
  • 63,078
  • 28
  • 122
  • 148
  • 5
    And if you're working together with others with whom you're not sharing a repository, and would therefore like to add the dependency to your SCM: consider creating a file-repository under the project-root, deploy your packaged dependency to that repository, reference the file repository in your project POM and add that the repository to revision control. – Tim Feb 07 '11 at 09:17
  • @Tim your comment deserves to be an additional answer. – Boris Pavlović Feb 07 '11 at 09:42
  • Well, I cannot fully agree with you. In source control I have more control on what's going on. – Tarlog Feb 07 '11 at 12:36
  • 1
    Thanks both. If the solution is clear enough as it is I'll leave it as a comment: I found out about this method through StackOverflow as well, so you should be able to find on SO. If not I'll elaborate in an answer, as I can't find the myself link right now.. – Tim Feb 07 '11 at 14:50