Building an executable jar with maven dependencies and external jars.

huangapple go评论78阅读模式
英文:

Building an executable jar with maven depencies and external jars

问题

我有一个应用程序,我在其中使用了Maven依赖项,同时还使用了一个位于我的计算机上的项目的外部JAR文件,该项目是手动添加到应用程序中的。问题是,每当我使用Maven导出项目时,它只导出所有Maven依赖项,而不是我手动包含的外部JAR文件。有没有办法可以导出它?

这是我的pom.xml:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>
                            ${project.build.directory}/libs
                        </outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>libs/</classpathPrefix>
                        <mainClass>
                            com.cristianruizblog.loginSecurity.LoginSecurityTutorialApplication
                        </mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

感谢阅读。如果有人能帮助,我会非常高兴!

英文:

I have an application where Im using maven dependecies and Im also using an external jar of a project which is located in my computer, the project is added to the application manually. The problem is whenever I export the project with maven, It only exports all maven dependencies, not the externatl jar that I have included manually. Is there anyway that I can export it?

Here is my pom.xml:

&lt;build&gt;
	&lt;plugins&gt;
		&lt;plugin&gt;
			&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
			&lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
			&lt;executions&gt;
				&lt;execution&gt;
					&lt;id&gt;copy-dependencies&lt;/id&gt;
					&lt;phase&gt;prepare-package&lt;/phase&gt;
					&lt;goals&gt;
						&lt;goal&gt;copy-dependencies&lt;/goal&gt;
					&lt;/goals&gt;
					&lt;configuration&gt;
						&lt;outputDirectory&gt;
							${project.build.directory}/libs
						&lt;/outputDirectory&gt;
					&lt;/configuration&gt;
				&lt;/execution&gt;
			&lt;/executions&gt;
		&lt;/plugin&gt;
		&lt;plugin&gt;
			&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
			&lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
			&lt;configuration&gt;
				&lt;archive&gt;
					&lt;manifest&gt;
						&lt;addClasspath&gt;true&lt;/addClasspath&gt;
						&lt;classpathPrefix&gt;libs/&lt;/classpathPrefix&gt;
						&lt;mainClass&gt;
							com.cristianruizblog.loginSecurity.LoginSecurityTutorialApplication
						&lt;/mainClass&gt;
					&lt;/manifest&gt;
				&lt;/archive&gt;
			&lt;/configuration&gt;
		&lt;/plugin&gt;
		&lt;plugin&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
		&lt;/plugin&gt;
	&lt;/plugins&gt;
&lt;/build&gt;

Thanks for reading. If anyone can help I would be so happy!

答案1

得分: 1

根据@M. Deunum所述,尝试将您的外部jar包放入Maven存储库中,以避免启用任何机器构建您的jar包。如果这不是一个选项,您可以使用Maven的系统依赖范围来包含这个jar包。请注意,这只是一个临时解决方案,因为这个范围已被标记为过时。

英文:

As stated by @M. Deunum, try to get your external jar into a Maven repository to avoid enable any machine to build your jar. If this is no option, you can use the Maven system dependency scope to include the jar. Note that this is only a temporary solution as this scope has been marked as depricated.

huangapple
  • 本文由 发表于 2020年8月11日 07:19:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/63349339.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定