Java 一个jar,包含一个类和dependecy jar中的主类
我有一个项目,有两个类,分别命名为Test1和Test2 Test1和Test2都不是主类。现在我有一个名为cloudexe.jar的依赖项,它有一个主类ClassExecuter。现在我的问题是希望ClassExecuter作为test1.jar和test2.jar的主类 test1.jar应仅包含test1类及其所有依赖项,包括cloudexe.jar类似地test2.jar应仅包含test2类及其所有依赖项,包括cloudexe.jar 现在,当我的包my pom.xml得到test1.jar和test2.jar时,我得到的结果如下所示Java 一个jar,包含一个类和dependecy jar中的主类,java,eclipse,maven,maven-assembly-plugin,onejar,Java,Eclipse,Maven,Maven Assembly Plugin,Onejar,我有一个项目,有两个类,分别命名为Test1和Test2 Test1和Test2都不是主类。现在我有一个名为cloudexe.jar的依赖项,它有一个主类ClassExecuter。现在我的问题是希望ClassExecuter作为test1.jar和test2.jar的主类 test1.jar应仅包含test1类及其所有依赖项,包括cloudexe.jar类似地test2.jar应仅包含test2类及其所有依赖项,包括cloudexe.jar 现在,当我的包my pom.xml得到test1.j
Exception in thread "main" java.lang.NoSuchMethodException: com.uber.Test1.main([Ljava.lang.String;)
at java.lang.Class.getMethod(Class.java:1678)
at com.simontuffs.onejar.Boot.run(Boot.java:339)
at com.simontuffs.onejar.Boot.main(Boot.java:166)
下面给出了我的pom.xml
<build>
<plugins>
<plugin>
<groupId>com.jolira</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<id>build-first</id>
<configuration>
<mainClass>com.uber.Test1</mainClass>
<attachToBuild>true</attachToBuild>
<classifier>onejar</classifier>
<filename>test1.jar</filename>
</configuration>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
<execution>
<id>build-second</id>
<configuration>
<mainClass>com.uber.Test2</mainClass>
<attachToBuild>true</attachToBuild>
<classifier>onejar</classifier>
<filename>test2.jar</filename>
</configuration>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>onejar-maven-plugin.googlecode.com</id>
<url>http://onejar-maven-plugin.googlecode.com/svn/mavenrepo</url>
</pluginRepository>
</pluginRepositories>
com.joira
onejar maven插件
1.4.4
先建
com.uber.Test1
真的
奥内贾尔
test1.jar
一罐
建立第二
com.uber.Test2
真的
奥内贾尔
test2.jar
一罐
onejar-maven-plugin.googlecode.com
http://onejar-maven-plugin.googlecode.com/svn/mavenrepo
任何人都可以在这方面帮助我吗您需要一位有两个子项目的家长:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>test1</module>
<module>test2</module>
</modules>
</project>
4.0.0
com.example
父母亲
1.0-快照
聚甲醛
测试1
测试2
然后您有两个项目test1和test2项目,它们将生成JAR,使用shade插件使其执行主类ClassExecuter:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>test1</artifactId>
<packaging>jar</packaging>
<dependencies>
... all your dependencies including cloudexe.jar
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>....ClassExecuter</Main-Class>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
4.0.0
com.example
父母亲
1.0-快照
测试1
罐子
... 包括cloudexe.jar在内的所有依赖项
org.apache.maven.plugins
maven编译器插件
1.8
1.8
org.apache.maven.plugins
maven阴影插件
3.0.0
包裹
阴凉处
…类执行器
感谢您的回复,但在其中pom.xml
我将定义模块test1 test2
您也需要了解maven多模块项目。你有一个父母,然后是两个孩子。每个孩子都在自己的目录中。构建父对象时,它将构建其每个子对象,在您的情况下,每个孩子的目标文件夹中都有一个可执行的jar。但是对于一个类,我需要创建一个模块项目……如果我有10个类……那么我需要创建10个模块项目……还有其他解决方案吗?我们可以使用maven assembly plugin
和onejar maven plugin
这样做吗它,我认为你需要再看看你的问题,解释一下为什么你需要这些主要的课程。