Maven:使用一个 Jar 中的所有依赖项进行编译

发布于 2024-10-10 03:28:08 字数 1506 浏览 1 评论 0原文

在项目的 pom 中,我添加了对scopecompile的依赖。这是一个 jar 文件,其中还包含一些类文件和 jar 文件。我当前的java文件需要依赖jar的内部jar来编译。

但是maven编译目标返回编译错误。 :banghead:

编译所需的所有 jar 都在依赖项中添加的单个 jar 文件中......................................

请帮我!

我的pom:

<project>
  <!-- ... -->
  <dependencies>
    <dependency>
      <groupId>eagle</groupId>
      <artifactId>zkui</artifactId>
      <version>360LTS</version>
      <type>jar</type>
      <scope>compile</scope>
    </dependency>
  </dependencies>
  <build>
    <sourceDirectory>./src/main/java</sourceDirectory>
    <outputDirectory>./target/classes</outputDirectory>
    <finalName>${project.groupId}-${project.artifactId}</finalName>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.2</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

错误:

包 org.zkoss.zk.ui 不存在 这个包 org.zkoss.zk.ui 在 jar 中 依赖文件 zkex.jar jar eagle:zkui:360LTS jar 文件

请帮助我!!!! :jumpingjoy:

提前谢谢

in pom of a project, i have added dependency with scope compile . which is a jar file which contains some class file and jar's as well. my current java file needs internal jars of dependent jar to compile.

But maven compile goal returning compilation error . :banghead:

All the jar's needed to compile are in the single jar file which is added in dependency.............................

Please help me!

my pom:

<project>
  <!-- ... -->
  <dependencies>
    <dependency>
      <groupId>eagle</groupId>
      <artifactId>zkui</artifactId>
      <version>360LTS</version>
      <type>jar</type>
      <scope>compile</scope>
    </dependency>
  </dependencies>
  <build>
    <sourceDirectory>./src/main/java</sourceDirectory>
    <outputDirectory>./target/classes</outputDirectory>
    <finalName>${project.groupId}-${project.artifactId}</finalName>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.2</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

error:

package org.zkoss.zk.ui does not exist
this package org.zkoss.zk.ui is in jar
file zkex.jar which is in dependency
jar eagle:zkui:360LTS jar file

Please Help ME!!!! :jumpingjoy:

Advance Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

红尘作伴 2024-10-17 03:28:08

好吧,我想你可以

  • 使用 dependency:unpack 将 jar 解压到 target/lib 左右(编译前)
  • 停用 compiler:compile 通过排除所有内容

    <前><代码><排除>
    <排除>**/*.java

  • 使用 antrun:run 与 ant javac 任务来编译源代码,如下所示(将执行绑定到阶段compile):

    <预置><代码><目标>

    <类路径>;

    >



但是,虽然这会帮助您编译应用程序,但它不会帮助您运行部署您的应用程序。

Well I guess you could

  • use dependency:unpack to unpack the jars to target/lib or so (before compile)
  • deactivate compiler:compile by excluding everything

    <excludes>
        <exclude>**/*.java</exclude>
    </exclude>
    
  • use antrun:run with the ant javac task to compile the sources, something like this (bind the execution to phase compile):

    <target>
        <javac srcdir="${project.build.sourceDirectory}"
               destdir="${project.build.outputDirectory}">
            <classpath>
                <pathelement path="${maven.compile.classpath}"/>
                <fileset dir="${project.build.directory}/lib">
                    <include name="**/*.jar"/>
                </fileset>
            </classpath>
        </javac> 
    </target>
    

However, while that would help you compile your application, it would not help you run or deploy your application.

鯉魚旗 2024-10-17 03:28:08

您可以使用该元素来执行此操作:

<dependencies>
    <dependency>
      <groupId>groep.does.not.matter</groupId>
      <artifactId>neither-does-artifactId</artifactId>
      <version>and.nor-does-version</version>
      <type>jar</type>
      <scope>system</scope>
      <systemPath>${project.baseDir}/lib/jarname.jar</systemPath>
    </dependency>
  </dependencies>

您需要引用(并在类路径中)的 jar 是 lib/jarname.jar,并且 lib 目录位于项目的根目录中。

You can use the element to do this:

<dependencies>
    <dependency>
      <groupId>groep.does.not.matter</groupId>
      <artifactId>neither-does-artifactId</artifactId>
      <version>and.nor-does-version</version>
      <type>jar</type>
      <scope>system</scope>
      <systemPath>${project.baseDir}/lib/jarname.jar</systemPath>
    </dependency>
  </dependencies>

where the jar you need to reference (and have in your classpath) is lib/jarname.jar, and the lib directory is in the root of your project.

水溶 2024-10-17 03:28:08

我相信您实际上没有使用正确的依赖项。 ZK 实际上有 Maven 存储库,如此处所述。

您需要检查您需要哪些依赖项。例如,对于 zkex,您需要类似以下内容:

    <dependency>
        <groupId>org.zkoss.zk</groupId>
        <artifactId>zkex</artifactId>
        <version>${zk.version}</version>
    </dependency>

您还需要添加 ZK Maven 存储库:

    <repositories>
        <repository>
            <id>zk repository</id>
            <url>http://mavensync.zkoss.org/maven2</url>
        </repository>
        <!-- If Using ZK EE or ZK PE Respository (not evaluation version), you need to add login info into ~/.m2/settings.xml -->
        <repository>
            <id>ZK PE Evaluation</id>
            <url>http://mavensync.zkoss.org/zk/pe-eval</url>
        </repository>
        <repository>
            <id>ZK EE Evaluation</id> 
            <url>http://mavensync.zkoss.org/zk/ee-eval</url>
        </repository>
    </repositories>

祝您好运! :-)

I believe you're actually not using the proper dependencies. ZK actually have Maven repositories as described here.

You need to check which dependencies you need. For example for zkex, you would need something like:

    <dependency>
        <groupId>org.zkoss.zk</groupId>
        <artifactId>zkex</artifactId>
        <version>${zk.version}</version>
    </dependency>

You will also need to add the ZK Maven repositories:

    <repositories>
        <repository>
            <id>zk repository</id>
            <url>http://mavensync.zkoss.org/maven2</url>
        </repository>
        <!-- If Using ZK EE or ZK PE Respository (not evaluation version), you need to add login info into ~/.m2/settings.xml -->
        <repository>
            <id>ZK PE Evaluation</id>
            <url>http://mavensync.zkoss.org/zk/pe-eval</url>
        </repository>
        <repository>
            <id>ZK EE Evaluation</id> 
            <url>http://mavensync.zkoss.org/zk/ee-eval</url>
        </repository>
    </repositories>

Good luck! :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文