我想将我在JAR中的源代码与所有依赖项结合起来,并将其与其他文件一起打包成一个zip文件.我能够创建一个包含所有依赖项的Jar以及ZIP文件,但我无法将两者结合起来.
我最终想要zip文件中的以下目录结构:
装载机/斌/ shellscript.sh
装载器/ LIB /罐与 - dependencies.jar
装载器/应用程序的名字/配置/ config.xml中
这是我的pom文件的摘录:
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
这是我装配的摘录
<assembly>
<id>bin</id>
<!-- Specifies that our binary distribution is a zip package -->
<formats>
<format>zip</format>
</formats>
<baseDirectory>SpreadsheetLoaderApp</baseDirectory>
<fileSets>
<fileSet>
<directory>corporatebondpurchases</directory>
<outputDirectory>${basedir}/corporatebondpurchases/config</outputDirectory>
<includes>
<include>*.xml</include>
<include>*.properties</include>
</includes>
</fileSet>
<fileSet>
<directory>corporatebondpurchases</directory>
<outputDirectory>${basedir}/bin</outputDirectory>
<includes>
<include>*.sh</include>
</includes>
</fileSet>
</fileSets>
</assembly>
Run Code Online (Sandbox Code Playgroud)
以下是部分构建的输出:
[INFO] --- maven-assembly-plugin:2.4:single (default-cli) @ SpreadsheetLoader ---
[INFO] Reading assembly descriptor: src/main/assembly/assembly.xml
[INFO] Building …Run Code Online (Sandbox Code Playgroud) 我没有得到这个代码的任何错误.只是我想要排除的文件仍然被添加.我正在使用maven插件进行eclipse
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>only</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>com.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<excludes>
<exclude>**/com/uiservices/controllers/*.* </exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud) 默认情况下,maven编译器插件将编译后的类放入${project.build.directory}/classes.我想把它们放进去${project.build.directory}/myclasses.参数-d更改已编译类的目标.我配置了插件但是我收到了一个错误:javac: directory not found: C:\home\target/myclasses.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<showDeprecation>true</showDeprecation>
<compilerArguments>
<d>${project.build.directory}/myclasses</d>
</compilerArguments>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud) 由于某种原因,此命令在我的本地计算机上运行良好:
mvn clean install -DskipTests=true -Psdk
Run Code Online (Sandbox Code Playgroud)
然而,对于 Codeship,它现在可以工作并抛出此“找不到符号”错误。在 Codeship 中完整的命令是:
jdk_switcher use oraclejdk8
echo $JAVA_HOME
mvn clean install -DskipTests=true -Psdk
Run Code Online (Sandbox Code Playgroud)
在 POM 存储库中有这样的内容:
mvn clean install -DskipTests=true -Psdk
Run Code Online (Sandbox Code Playgroud)
错误:
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ client-app ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 65 source files to /home/rof/src/bitbucket.org/company/client-app/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/rof/src/bitbucket.org/company/client-app/src/main/java/com/client/rest/resources/MyResource.java:[3,61] cannot find symbol
symbol: class MyEntity
Run Code Online (Sandbox Code Playgroud) 我遇到一个具有以下2个依赖项的问题:
org.apache.felix»org.apache.felix.utils»1.6.0
和
com.github.rotty3000»phidias»0.3.2
它们都对org.osgi.core具有传递依赖关系,felix依赖于版本4.1.0,phidias依赖于版本5.0.0
我们需要版本5.0.0才能正确编译我们的代码
如果我将依赖项设为:
<dependencies>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.utils</artifactId>
<version>1.6.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.rotty3000</groupId>
<artifactId>phidias</artifactId>
<version>0.3.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
maven自动获取版本4.1.0,导致编译错误。如果我将phidias放在felix之上,它将获得版本5.0.0并可以正常编译。
我们要按字母顺序对依赖项进行排序,以便felix排在最前面,是否仍然有必要强制osgi.core解析5.0.0版本?
谢谢!
我很困惑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>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
为什么我必须指定两次依赖?我该如何使用这三个标签?
我是maven的新手,它是一门有趣的学科。使用以下命令成功创建具有依赖项的jar:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
现在,我必须包括一些shell脚本和生成的jar到tar中。为此,我尝试了以下方法:已添加
<descriptors>
<descriptor>hadoop-job.xml</descriptor>
</descriptors>
Run Code Online (Sandbox Code Playgroud)
以上脚本。
在hadoop-job.xml中,我将所需文件包含到tar中。
问题是tar首先生成,并说在目标中找不到* .jar。因为这两个配置都位于程序集插件中,所以是否有办法先安排jar创建,然后安排tar。还是有一个命令先执行并生成jar,然后再生成tar命令?
顺便说一句,我正在执行mvn clean assembly:assembly -Dbinary = true。帮我解决。谢谢。