【发布时间】:2015-06-05 19:47:37
【问题描述】:
我在 Eclipse 中使用 Eclipse Maven (m2e),我正在像这样运行我的项目:
我的pom.xml 看起来像这样:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ro.project</groupId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>ro.project</name>
<properties>
<org.springframework.version>3.1.1.RELEASE</org.springframework.version>
<org.hibernate.version>4.1.0.Final</org.hibernate.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>ro.project.ProjectServer</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.7.0_02</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
<executions>
<execution>
<id>ant-magic</id>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<property name="compile_classpath" refid="maven.compile.classpath" />
<property name="runtime_classpath" refid="maven.runtime.classpath" />
<property name="test_classpath" refid="maven.test.classpath" />
<property name="plugin_classpath" refid="maven.plugin.classpath" />
<ant antfile="${basedir}/clientExport.xml" target="export-all" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<artifactId>project-core</artifactId>
<url>http://www.project.ro</url>
</project>
在我运行 maven 安装后,它正在工作......
Maven 运行配置:
问题是我生成的.jar 它没有包含依赖项......
我如何配置pom.xml 以包含.jar 格式的所有依赖项而不是解压缩.. 因为似乎解压缩不正确...
为了确保包括所有 jar 都可以。我下载每个库并将其添加到 jar 的 /lib 文件夹中,并且 jar 正在运行...所以.. 我唯一的问题是:我该如何配置pom.xml 以便以jar 格式添加我的所有依赖项?
我尝试了所有方法:
assembly:assemblyassembly:single-
assembly:single带有我的描述符(assemble.xml文件),但它不起作用 -
maven copy dependencies插件,但仍然无法使用 Eclipse Maven -m2e
我没有解决方案...谁能告诉我在 jar 中添加依赖项的正确方法?我不敢相信maven 如此复杂,我到处都找不到我的问题的答案..
提前谢谢你
【问题讨论】:
-
除非你有一个 jar 加载类加载器,否则你不能像你想要做的那样嵌套 jars。
-
我要像 java -jar myjar 一样运行它
标签: java maven dependencies maven-3 m2eclipse