向JAR添加依赖项

时间:2019-03-04 03:35:19

标签: jar dependencies

下面是我的maven项目的POM,它在项目构建期间生成一个JAR“ sngavara-upnetworkstatus.jar”并将其复制到bin文件夹。 请注意,我的项目具有依赖性-已存储。

如何使我的JAR访问类来自“已存储”依赖项? 我试图在JAR中添加一些代码,为此我需要使用来自cellred依赖项的类。当我运行它时,它给了我NoClassDefFoundError。但是,Eclipse中没有编译时错误。

请帮助。

<build>
        <finalName>${artifactId}</finalName>
        <plugins>

        <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <executions>
                    <execution>
                        <id>upnetworkstatus</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration>
                            <archive>
                                <manifest>
                                    <mainClass>
                                        com.ezmediation.driver.sngavara.upnetworkstatus.App
                                    </mainClass>
                                </manifest>
                            </archive>
                            <classifier>upnetworkstatus</classifier>
                            <includes>
                            </includes>

                        </configuration>
                    </execution>

                </executions>
            </plugin>           
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>
                                <copy file="target/avarasnga-upnetworkstatus.jar" tofile="bin/sngavara-upnetworkstatus.jar" />
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

  <dependencies>             
    <dependency>
      <groupId>com.ezmediation</groupId>        
      <artifactId>cellred</artifactId>        
      <version>${project.version}</version>
      <scope>provided</scope>     
   </dependency>
  </dependencies>

0 个答案:

没有答案