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

前端 未结 24 2880
萌比男神i
萌比男神i 2020-11-22 01:41

Maven2 is driving me crazy during the experimentation / quick and dirty mock-up phase of development.

I have a pom.xml file that defines the dependenc

24条回答
  •  轮回少年
    2020-11-22 01:53

    I just wanted a quick and dirty workaround... I couldn't run the script from Nikita Volkov: syntax error + it requires a strict format for the jar names.

    I made this Perl script which works with whatever format for the jar file names, and it generates the dependencies in an xml so it can be copy pasted directly in a pom.

    If you want to use it, make sure you understand what the script is doing, you may need to change the lib folder and the value for the groupId or artifactId...

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    open(my $fh, '>', 'dependencies.xml') or die "Could not open file 'dependencies.xml' $!";
    foreach my $file (glob("lib/*.jar")) {
        print "$file\n";
        my $groupId = "my.mess";
        my $artifactId = "";
        my $version = "0.1-SNAPSHOT";
        if ($file =~ /\/([^\/]*?)(-([0-9v\._]*))?\.jar$/) {
            $artifactId = $1;
            if (defined($3)) {
                $version = $3;
            }
            `mvn install:install-file -Dfile=$file -DgroupId=$groupId -DartifactId=$artifactId -Dversion=$version -Dpackaging=jar`;
            print $fh "\n\t$groupId\n\t$artifactId\n\t$version\n\n";
            print " => $groupId:$artifactId:$version\n";
        } else {
            print "##### BEUH...\n";
        }
    }
    close $fh;
    

提交回复
热议问题