使用 maven 将打包好的私有依赖安装到本地 repository

使用 maven 将打包好的私有依赖安装到本地 repository

Install jar

要将打包好的 JAR 包和源代码包(source package)安装到本地 Maven 存储库(repository)中,您可以使用 Maven 的 install 目标。以下是如何执行此操作的步骤:
1. 打开命令行终端。
2. 确保您已经进入了包含Maven项目的根目录。
3. 运行以下 Maven 命令,使用 install 目标将 JAR 包和源代码包安装到本地存储库中:

mvn install:install-file -Dfile=path/to/your-artifact.jar -DgroupId=your.groupId -DartifactId=your-artifactId -Dversion=your-version -Dpackaging=jar

请将上述命令中的以下内容替换为您的项目信息:
* path/to/your-artifact.jar:JAR包的路径。
* your.groupId:您的项目的groupId。
* your-artifactId:您的项目的artifactId。
* your-version:您的项目的版本号。
* jar:打包类型,如果是源代码包,则将 packaging 更改为 jar

执行此命令后,Maven 将会将指定的 JAR 包和源代码包复制到本地 Maven 存储库中(通常是 ~/.m2/repository ),可以在项目中引用它们。确保您的 Maven 配置正确,以便项目可以找到这些依赖项。

请注意,如果您的项目已经使用 Maven 进行构建,通常不需要手动安装 JAR 包和源代码包到本地存储库。Maven 会自动处理依赖项的安装和下载。手动安装通常只在某些特殊情况下使用。

Install pom

和上面基本一样,只是 packagingpomfile 为文件 pom 路径。

Install sources

和上面 jar install 基本一样,packaging 还是为 jar,还要加 -Dclassifier=sources.

mvn install:install-file -Dfile=path/to/your-artifact-sources.jar -DgroupId=your.groupId -DartifactId=your-artifactId -Dversion=your-version -Dpackaging=jar -Dclassifier=sources

确保替换上述命令中的以下内容:
* path/to/your-artifact-sources.jar:源代码JAR包的路径。
* your.groupId:您的项目的groupId。
* your-artifactId:您的项目的artifactId。
* your-version:您的项目的版本号。

执行此命令后,Maven 将源代码 JAR 包安装到本地 Maven 存储库中,并使用 classifier sources 来标识它是源代码包。之后,您可以在 Maven 项目中引用这个源代码包作为依赖项。

示例

#!/usr/bin/env bash

set -x

file=
groupId=xxx
artifactId=
version=xxx
packaging=
classifier=

mvn_install() {
  mvn install:install-file -Dfile=${file} -DgroupId=${groupId} -DartifactId=${artifactId} -Dversion=${version} -Dpackaging=${packaging} || exit 1
}

mvn_install_classifier() {
  mvn install:install-file -Dfile=${file} -DgroupId=${groupId} -DartifactId=${artifactId} -Dversion=${version} -Dpackaging=${packaging} -Dclassifier=${classifier} || exit 1
}

mvn_install_3() {
  file=${artifactId}-${version}.pom
  artifactId=${artifactId}
  packaging=pom
  mvn_install || exit 1

  file=${artifactId}-${version}.jar
  artifactId=${artifactId}
  packaging=jar
  mvn_install || exit 1

  file=${artifactId}-${version}-sources.jar
  artifactId=${artifactId}
  packaging=jar
  classifier=sources
  mvn_install_classifier || exit 1
}

artifactIds_3=(
  xxx
  yyy
)

for a in "${artifactIds_3[@]}"; do
  artifactId=${a}
  mvn_install_3 || exit 1
done


artifactIds_1=(
  zzz
  nnn
)

for a in "${artifactIds_1[@]}"; do
  artifactId=${a}
  file=${artifactId}-${version}.pom
  packaging=pom
  mvn_install || exit 1
done

compiling ace (linux)

compiling ace (linux)

  • fast download (2020-04-05)

e.g.

# ACE-x.y.z.tar.bz2
axel -an 32 http://download.dre.vanderbilt.edu/previous_versions/ACE-6.2.1.tar.bz2

# or
axel -an 32 http://download.dre.vanderbilt.edu/previous_versions/ACE-6.4.0.tar.bz2
  • unpack and prepare
# unpack
cd /path/to/wrapper/repo/root
git checkout v6.2.1

# or:
tar -xf ACE-6.2.1.tar.bz2
cd ACE_wrappers/

# prepare
# set the environment variable ACE_ROOT to point to the directory where ace is
# unpacked, update your .bashrc accordingly e.g.:
export ACE_ROOT=$(pwd)

# Build a symlink to config.h as (config.h is in ACE_wrappers/ace):
cd $ACE_ROOT/ace

# and (which can be found in ACE_wrappers/include/makeinclude):
cd $ACE_ROOT/include/makeinclude
ln -s platform_linux.GNU platform_macros.GNU
  • compile
cd $ACE_ROOT/ace
make clean
make -j
  • install
cd $ACE_ROOT
sudo -s bash
export ACE_ROOT=$(pwd)

# If you wish to install ACE (using "make install"), set the installation
# prefix in platform_macros.GNU.
cd $ACE_ROOT/include/makeinclude

# INSTALL_PREFIX = /opt/lib/ace-6.2.1

cd $ACE_ROOT/ace
make install

# cleanup
make clean

sudo rm -rf *

exit

git checkout -- .
  • pack
cd /opt/lib/ace6.2.1

tar -cjf ../ace6.2.1-xenial-amd64.tar.bz2 .

refs

install pre-built debian package (16.04)

curl -s https://yuiwong.org/debrepo/setup/setup-ubuntu-deb.sh | sudo bash

sudo apt update
sudo apt install libace6.2.1-nonofficial-dev

Find missing number (in C++)

Find missing number

Like the missing number problem, but given a list of N integers and these integers are in the range of [X, Y].
There are no duplicates in list. Maybe one or more than one of the integers is missing in the list.
Write an efficient code to find the first missing integer

— use binary search method:

/**
 * find the missing number (the first one) in a sorted array (min to max).
 * @tparam T integral value type,
 * @param nums the sorted numbers to find missing number.
 * @param nNums number count of @a nums.
 * @param rangeMin to find the number is this range.
 * @param rangeMax to find the number is this range.
 * @param[out] result result when success.
 * @return true when success, false when params invalid.
 *
 * @note
 * - @a nums should NOT nil, valid and sorted.
 * - @a nNums should valid.
 * - rangeMin should less than rangeMax!
 */
template<typename T>
typename CPPBASE2_ENABLE_IF<CPPBASE2_IS_INTEGRAL<T>::value, bool>::type
searchFirstMissingNumber(
  const T* const nums,
  const size_t nNums,
  const T rangeMin,
  const T rangeMax,
  T& result) {
  if ((!nums) || (rangeMin >= rangeMax)) {
    return false;
  }
  const T n = (rangeMax - rangeMin) + 1;
  if (uint64_t(n) <= nNums) {
    return false;
  }
  if (nNums < 1) {
    result = rangeMin;
    return true;
  }

  size_t leftIdx = 0;
  size_t rightIdx = nNums - 1;
  T expectMin = rangeMin;
  //T expectMax = rangeMax;
  size_t midIdx;
  T expectMid;

  // e.g.1: [0, 9], {0, 1, 2, 3, 5, 6, 7, 8, 9}
  //     2: [0, 9], {0, 1, 2, 4, 5, 6, 7, 8, 9}
  //     3: [0, 9], {0, 1, 2, 3, 4, 6, 7, 8, 9}
  //     4: [0, 9], {7, 8}
  //     5: [0, 9], {9}
  //     6: [0, 9], {0}
  //     7: [0, 9], {0, 1, 2, 3, 4, 5, 7, 8, 9}
  //     8: [-3, 5], {-3, -2, -1, 2, 3, 4, 5}
  while (leftIdx <= rightIdx) {
    if (nums[leftIdx] > expectMin) {
      result = expectMin;
      return true;
    } else {
      midIdx = (leftIdx + rightIdx) / 2;
      expectMid = rangeMin + midIdx;
      const T& midNum = nums[midIdx];
      if ((midNum == expectMid)
        && ((midIdx >= rightIdx) || ((expectMid + 1) != nums[midIdx + 1]))) {
        result = expectMid + 1;
        return true;
      } else if (midNum > expectMid) {
        // search left
        rightIdx = midIdx - 1;
        //expectMax = midNum - 1;
        continue;
      }
      // search right
      leftIdx = midIdx + 1;
      expectMin = midNum + 1;
    }
  }

  throw std::logic_error("bug!");
  return false;
}

some test code:

TEST(m, large) {
  const int N = 1024 * 1024 * 100;
  std::vector<int> a;
  a.reserve(N);
  SteadyTime t1, t2;

  const Duration maxET = Duration::milliseconds(1);
  Duration sum1, sum2;

  for (int k = 0; k < 100; ++k) {
    int missingNumber = kRg->get32() % a.capacity();
    int missingNumber2 = kRg->get32() % a.capacity();
    if (missingNumber > missingNumber2) {
      std::swap(missingNumber, missingNumber2);
    }
    int offset = kRg->get32() % a.capacity();
    if (k % 2) {
      offset *= -1;
    }
    a.clear();
    for (int i = 0; i < N; ++i) {
      if (i != missingNumber && i != missingNumber2) {
        a.push_back(offset + i);
      }
    }
    int result = -1;
    t1 = SteadyTime::now();
    EXPECT_TRUE(algorithm::searchFirstMissingNumberSlow(
      a.data(), a.size(), offset, offset + (N - 1), result));
    t2 = SteadyTime::now();
    sum1 += (t2 - t1);

    EXPECT_EQ(offset + missingNumber, result);
    EXPECT_LE((t2 - t1), Duration::milliseconds(100));

    CPPBASE2_INFO("searchFirstMissingNumberSlow"
           " size " << a.size()
      << ", elapsed time " << (t2 - t1).toNanosec() << " ns, "
      << ", result = " << (offset + missingNumber));

    result = -1;
    t1 = SteadyTime::now();
    EXPECT_TRUE(algorithm::searchFirstMissingNumber(
      a.data(), a.size(), offset, offset + (N - 1), result));
    t2 = SteadyTime::now();
    sum2 += (t2 - t1);

    EXPECT_EQ(offset + missingNumber, result);
    EXPECT_LE((t2 - t1), maxET);

    CPPBASE2_INFO("searchFirstMissingNumber"
           " size " << a.size()
      << ", elapsed time " << (t2 - t1).toNanosec() << " ns, "
      << ", result = " << (offset + missingNumber));
  }

  EXPECT_LE((sum1.toNanosec() / 100), Duration::milliseconds(20).toNanosec());
  EXPECT_GE((sum1.toNanosec() / 100), Duration::milliseconds(5).toNanosec());
  EXPECT_LE((sum2.toNanosec() / 100), Duration::microseconds(10).toNanosec());
}