Add compiled java class to a maven project

前端 未结 2 1422
半阙折子戏
半阙折子戏 2020-12-10 06:28

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 upload

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-10 07:05

    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:

    
        
            file.repo
            file://${project.basedir}/repo
        
    
    

    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.

提交回复
热议问题