不从name-sources.jar导入类

时间:2021-05-09 19:36:26

I have created a maven war project, and want to call it from another module (war). When I searched found that name-sources.jar file is used as dependency to another module. I am adding dependency of name-sources but import is not working.

我创建了一个maven war项目,并希望从另一个模块(war)调用它。当我搜索时发现name-sources.jar文件被用作对另一个模块的依赖。我正在添加name-sources的依赖项,但import不起作用。

name-SNAPSHOT.war
name-SNAPSHOT-sources.jar 

are the files generated on building of maven project. Below is the dependency added into another module.

是构建maven项目时生成的文件。下面是添加到另一个模块的依赖项。

<dependency>
<groupId>uniqueid</groupId>
<artifactId>name</artifactId>
<version>8.9-SNAPSHOT</version>         
<classifier>sources</classifier>
        <scope>system</scope>
        <systemPath>{Path}/name-8.9-SNAPSHOT-sources.jar</systemPath>
 </dependency>

Any help is highly appreciated.

任何帮助都非常感谢。

2 个解决方案

#1


1  

I understand this: you have 2 web projects A and B, both with maven packaging = war. In A, there are classes you want to use in B.

我理解这一点:你有两个网络项目A和B,都有maven包装=战争。在A中,您要在B中使用类。

Forget about adding a *-sources.jar as dependency.

忘记添加* -sources.jar作为依赖项。

So, do this:

所以,这样做:

  1. generate a new maven project C as a library with project packaging "jar"
  2. 生成一个新的maven项目C作为一个项目包装“jar”的库

  3. Move the classes you want to share from A to C
  4. 将要共享的类从A移动到C.

  5. Install this artifact C in your local maven repository (mvn install)
  6. 在本地maven存储库中安装此工件C(mvn install)

  7. Then, add a dependency to C in the pom.xmls of A and B:
  8. 然后,在A和B的pom.xmls中为C添加依赖项:

<dependency>
    <groupId>your.group</groupId>
    <artifactId>yourLibrary</artifactId>
    <version>0.1.0-SNAPSHOT</version>
    <scope>compile</compile> <!-- this is default, so this line is optional-->
</dependency>

#2


0  

Created *-classes.jar file. Use below code under pom.xml:

创建了* -classes.jar文件。在pom.xml下使用以下代码:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.3</version>
  <configuration>                    
    <attachClasses>true</attachClasses>
 </configuration>
</plugin>

And added this new jar as dependency wherever want to use.

并在任何想要使用的地方添加了这个新的jar作为依赖。

<dependency>
        <groupId>com.honeywell.dras.sensibo</groupId>
        <artifactId>sensibo-client</artifactId>
        <version>{*}</version>          
        <classifier>classes</classifier>
</dependency>   

So advantage with this is we can generate both war and jar files and make use of both based on need.

这样做的好处是我们可以生成war和jar文件,并根据需要使用它们。

#1


1  

I understand this: you have 2 web projects A and B, both with maven packaging = war. In A, there are classes you want to use in B.

我理解这一点:你有两个网络项目A和B,都有maven包装=战争。在A中,您要在B中使用类。

Forget about adding a *-sources.jar as dependency.

忘记添加* -sources.jar作为依赖项。

So, do this:

所以,这样做:

  1. generate a new maven project C as a library with project packaging "jar"
  2. 生成一个新的maven项目C作为一个项目包装“jar”的库

  3. Move the classes you want to share from A to C
  4. 将要共享的类从A移动到C.

  5. Install this artifact C in your local maven repository (mvn install)
  6. 在本地maven存储库中安装此工件C(mvn install)

  7. Then, add a dependency to C in the pom.xmls of A and B:
  8. 然后,在A和B的pom.xmls中为C添加依赖项:

<dependency>
    <groupId>your.group</groupId>
    <artifactId>yourLibrary</artifactId>
    <version>0.1.0-SNAPSHOT</version>
    <scope>compile</compile> <!-- this is default, so this line is optional-->
</dependency>

#2


0  

Created *-classes.jar file. Use below code under pom.xml:

创建了* -classes.jar文件。在pom.xml下使用以下代码:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.3</version>
  <configuration>                    
    <attachClasses>true</attachClasses>
 </configuration>
</plugin>

And added this new jar as dependency wherever want to use.

并在任何想要使用的地方添加了这个新的jar作为依赖。

<dependency>
        <groupId>com.honeywell.dras.sensibo</groupId>
        <artifactId>sensibo-client</artifactId>
        <version>{*}</version>          
        <classifier>classes</classifier>
</dependency>   

So advantage with this is we can generate both war and jar files and make use of both based on need.

这样做的好处是我们可以生成war和jar文件,并根据需要使用它们。