简体   繁体   English

将非Maven项目转换为Maven

[英]Converting a non-maven project to maven

I am trying to convert and old non-maven java NetBeans project to a maven project. 我正在尝试将非Maven Java NetBeans项目转换为Maven项目。 The existing project has 36 libraries. 现有项目有36个图书馆。

What I did 我做了什么

  1. I outputted the library folder content to a file and got the list of all the jars. 我将库文件夹的内容输出到文件中,并获得了所有罐子的列表。
  2. I searched for the jar in maven repo and added the specific version as dependency in pom 我在maven repo中搜索了jar并将特定版本添加为pom中的依赖项

The Result 结果

The new maven project now has some new jars which the old one didn't have, probably they are added because they were the dependencies of the ones I added. 新的maven项目现在具有一些旧的jar,而旧的jar没有,可能是因为它们是我添加的依赖项而添加的。

My Questions 我的问题

  1. If the extra jars that are added in the "Dependencies" section are required by the jars that I added, how was the old project running? 如果我添加的jar需要在“依赖项”部分添加的额外jar,那么旧项目如何运行? ie without those jars included? 即不包括那些罐子?
  2. Some of the jars in the old project I believe were the dependencies of other jars. 我相信旧项目中的某些jar是其他jar的依赖项。 This I figured out when I added a jar and it added another jar by itself which I was about to add. 我在添加一个jar时发现了这个问题,它自己添加了另一个我要添加的jar。 So how do I figure out which jar is the dependency of which one so I don't explicitly specify that one in my pom? 那么,如何确定哪个jar是哪个jar的依存关系,因此我没有在pom中明确指定那个jar? or so I could add them in sequence. 或者我可以按顺序添加它们。

EDIT: 编辑:

Thanks to @SubOptimal, i was able to check the graph, but here is what I get: 感谢@SubOptimal,我能够检查图表,但这是我得到的:

在此处输入图片说明

On the left is the old project opened with all the libraries, on the right, is the newly maven converted project's graph opened. 左侧是打开了所有库的旧项目,右侧是打开了新的maven转换项目的图。 Now you can see the library is the same "axis2-kernel-1.6.1.jar". 现在您可以看到该库是相同的“ axis2-kernel-1.6.1.jar”。 On the left, the old project doesn't have the geronimo-ws-metadata_2.0_spec which is shown as a dependency of the axis2 library. 在左侧,旧项目没有geronimo-ws-metadata_2.0_spec,它显示为axis2库的依赖项。

Now my question is the same, how was the old project working, is this an optional dependency? 现在我的问题是一样的,旧项目是如何工作的,这是一个可选的依赖项吗?

The new dependencies might be there because of different library version in the old non-maven project and the new maven project. 由于旧的非Maven项目和新的Maven项目中的库版本不同,因此可能存在新的依赖项。

Assume the non-maven project would have used JUnit in version 3.8. 假设非Maven项目将在3.8版中使用JUnit。

pom.xml pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>sub.optimal</groupId>
    <artifactId>foo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
</project>

in this example you would have only JUnit as dependency 在此示例中,您只有JUnit作为依赖项

mvn dependency:tree

output 输出

[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ suboptimal ---
[INFO] com.example:suboptimal:jar:0.0.1-SNAPSHOT
[INFO] \- junit:junit:jar:3.8:test

If you now in the maven project would use version 4.12 (instead of the previous 3.8) you would see following dependencies (after changing the version number in the pom.xml ) 如果您现在在maven项目中将使用版本4.12(而不是以前的3.8),则会看到以下依赖项(在pom.xml更改版本号之后)

<groupId>junit</groupId>
    <artifactId>junit</artifactId>
<version>4.12</version>

output would be 输出将是

[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ suboptimal ---
[INFO] com.example:suboptimal:jar:0.0.1-SNAPSHOT
[INFO] \- junit:junit:jar:4.12:test
[INFO]    \- org.hamcrest:hamcrest-core:jar:1.3:test

For the shown dependency junit:junit:jar:4.12:test the test means it's not a runtime dependency. 对于所示的依赖项junit:junit:jar:4.12:test test表明它不是运行时依赖项。 It's need to run the provided tests. 需要运行提供的测试。

In Netbeans you would see now both as a test dependency 在Netbeans中,您现在都将两者视为测试依赖项

在此处输入图片说明

There is another way to show the dependencies directly in Netbeans. 还有另一种方法可以直接在Netbeans中显示依赖关系。 When you open the pom.xml click on Graph and only for the first time after you open it on Show Graph . 当您打开pom.xml请单击Graph ,只有在Show Graph上打开它之后才第一次。

显示依赖图

You get a visual dependency tree 您会得到一个视觉依赖树

依赖树

edit: You have not yet said what your old project uses. 编辑:您还没有说您的旧项目使用什么。 But find one example for the axis2 kernel below. 但是,请在下面找到axis2 kernel一个示例。

When your new project add following dependency 当您的新项目添加以下依赖项时

<dependency>
    <groupId>org.apache.axis2</groupId>
    <artifactId>axis2-kernel</artifactId>
    <version>1.6.1</version>
</dependency>

listing the dependencies with mvn dependency:tree reveals following compile time dependencies (needed also for the runtime, see Maven dependency scopes ) 列出具有mvn dependency:tree显示以下compile time依赖关系(运行时也需要,请参见Maven依赖关系范围

[INFO] \- org.apache.axis2:axis2-kernel:jar:1.6.1:compile
[INFO]    +- org.apache.ws.commons.axiom:axiom-api:jar:1.2.12:compile
[INFO]    |  +- org.apache.geronimo.specs:geronimo-activation_1.1_spec:jar:1.0.2:compile
[INFO]    |  +- org.apache.geronimo.specs:geronimo-javamail_1.4_spec:jar:1.6:compile
[INFO]    |  +- jaxen:jaxen:jar:1.1.1:compile
[INFO]    |  \- org.apache.geronimo.specs:geronimo-stax-api_1.0_spec:jar:1.0.1:compile
[INFO]    +- org.apache.ws.commons.axiom:axiom-impl:jar:1.2.12:compile
[INFO]    |  \- org.codehaus.woodstox:wstx-asl:jar:3.2.9:compile
[INFO]    +- org.apache.geronimo.specs:geronimo-ws-metadata_2.0_spec:jar:1.1.2:compile
[INFO]    +- org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1:compile
[INFO]    +- javax.servlet:servlet-api:jar:2.3:compile
[INFO]    +- commons-httpclient:commons-httpclient:jar:3.1:compile
[INFO]    |  \- commons-codec:commons-codec:jar:1.2:compile
[INFO]    +- commons-fileupload:commons-fileupload:jar:1.2:compile
[INFO]    +- wsdl4j:wsdl4j:jar:1.6.2:compile
[INFO]    +- org.apache.ws.commons.schema:XmlSchema:jar:1.4.7:compile
[INFO]    +- org.apache.neethi:neethi:jar:3.0.1:compile
[INFO]    +- org.apache.woden:woden-api:jar:1.0M9:compile
[INFO]    +- org.apache.woden:woden-impl-dom:jar:1.0M9:compile
[INFO]    |  \- org.apache.woden:woden-impl-commons:jar:1.0M9:compile
[INFO]    +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO]    \- javax.ws.rs:jsr311-api:jar:1.0:compile

So why it looks now your old project was not needing them? 那么,为什么现在看来您的旧项目不再需要它们了? Assuming that your old project uses the axis2.war file (extracted from axis2-1.6.1-war.zip ). 假设您的旧项目使用axis2.war文件(摘自axis2-1.6.1-war.zip )。 The dependencies are embedded. 依赖项已嵌入。

jar -tf axis2.war | grep geronimo-ws-metadata

output 输出

WEB-INF/lib/geronimo-ws-metadata-LICENSE.txt
WEB-INF/lib/geronimo-ws-metadata_2.0_spec-1.1.2.jar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM