Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
maven在jar中嵌入依赖项工件代码_Maven - Fatal编程技术网

maven在jar中嵌入依赖项工件代码

maven在jar中嵌入依赖项工件代码,maven,Maven,我有一个多模块maven项目。我有一个主要的“基本代码”模块,它创建了一个包含项目中所有编译源代码的jar 我有另一个模块,“可执行文件”,它从相同的源代码创建一个可执行jar。为了避免重复,我想从“基本代码”模块中提取类 我认为我所要做的就是使“基本代码”模块成为“可执行”模块的一个依赖项。但我只得到一个空罐子。我做错了什么? (我的“可执行”pom如下) 4.0.0 com.myproject/groupId> 我的项目 1. 可执行 罐子 com.myproject/groupId> 代

我有一个多模块maven项目。我有一个主要的“基本代码”模块,它创建了一个包含项目中所有编译源代码的jar

我有另一个模块,“可执行文件”,它从相同的源代码创建一个可执行jar。为了避免重复,我想从“基本代码”模块中提取类

我认为我所要做的就是使“基本代码”模块成为“可执行”模块的一个依赖项。但我只得到一个空罐子。我做错了什么? (我的“可执行”pom如下)


4.0.0
com.myproject/groupId>
我的项目
1.
可执行
罐子
com.myproject/groupId>
代码库
1.
org.apache.maven.plugins
maven jar插件
2.4
可运行
com.myproject.Main
真的
解放党/

您正在寻找的可能是uber jar:一个包含所有嵌入jar依赖项的jar文件,maven assembly插件的最新版本支持将其作为4个预定义描述符之一,请查看

尝试使用maven assembly插件替换maven jar插件,如下所示:

<!-- Create single executable jar with all dependencies unpacked and embedded -->
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
      <archive>
        <manifest>
          <mainClass>com.myproject.Main</mainClass>
          <addClasspath>true</addClasspath>
          <classpathPrefix>lib/</classpathPrefix>
        </manifest>
      </archive>
      <descriptorRefs><descriptorRef>jar-with-dependencies</descriptorRef></descriptorRefs>
    </configuration>
    <executions>
      <execution>
        <phase>package</phase>
        <goals><goal>single</goal></goals>
      </execution>
    </executions>
  </plugin>

org.apache.maven.plugins
这样做


希望有帮助。

您正在寻找的可能是uber jar:一个包含所有嵌入jar依赖项的jar文件,最新版本的maven assembly插件支持将其作为4个预定义描述符之一,请查看

尝试使用maven assembly插件替换maven jar插件,如下所示:

<!-- Create single executable jar with all dependencies unpacked and embedded -->
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
      <archive>
        <manifest>
          <mainClass>com.myproject.Main</mainClass>
          <addClasspath>true</addClasspath>
          <classpathPrefix>lib/</classpathPrefix>
        </manifest>
      </archive>
      <descriptorRefs><descriptorRef>jar-with-dependencies</descriptorRef></descriptorRefs>
    </configuration>
    <executions>
      <execution>
        <phase>package</phase>
        <goals><goal>single</goal></goals>
      </execution>
    </executions>
  </plugin>

org.apache.maven.plugins
这样做


希望这能有所帮助。

com.myproject.Main位于基本代码模块或可执行模块内的什么位置?它位于基本代码模块内,这就是为什么我认为正确的方法是以某种方式将其作为依赖项引入com.myproject.Main位于何处,在基本代码模块或可执行模块内部?它位于基本代码模块内部,这就是为什么我认为正确的方法是以某种方式将其作为依赖项引入