Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

convert ANT build.XML file into Maven pom.xml  RSS feed

 
ramesh merugu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please convert ANT build.XML file into Maven pom.xml.
Please help me.
I am new to maven
IMG_20170909_215047_773.jpg
[Thumbnail for IMG_20170909_215047_773.jpg]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37180
515
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramesh,
Welcome to CodeRanch!

I recommend starting small.

First, can you create an empty project with a POM like this (substitute the group id and artifact id you want to use). Running it should create an empty jar if you have your Maven configured correctly.



2) Create the src/main/java directory and put your source code in there. Similarly with src/test/java if you have tests. (and src/main/resources if you have resource files)

3) Run again and you'll get a load of compiler errors.

4) Start adding dependencies from Maven Central for your open source jars. Re-run Maven periodically so you can see how you are doing.

5) Customize the manifest to add the main class.

Give it a shot and reply with specifically what you get stuck on.
 
ramesh merugu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have added src/main/app.java
src/test/apptest.java
src/com/middleoffice/1.utils
                              /2.webservices





pom-result.jpg
[Thumbnail for pom-result.jpg]
newjpg.jpg
[Thumbnail for newjpg.jpg]
 
ramesh merugu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
src.com.middleoffice.webservices is my company requirement,
please the manifest,main class,classpath as per ant build.xml.
please please.
 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We are not a code mill. We will gladly help you out, but we won't do the work for you.

You already have the main class and manifest. You can verify by going to the project's target folder and opening the created JAR file with a ZIP program like 7Zip. If you want to change the name of the file (e.g. to remove the version) by adding a <finalName>${project.artifactId}</finalName> element to your JAR plugin's configuration.

However, that still leaves the class path, and that's I think where you should stop doing it the Ant way. With a class path entry you require all libraries to be located relatively to it. Instead, using the Shade Plugin, you can package them all inside your own JAR file, together with your own classes. That way you will only have one JAR to distribute. Note that you will need to add all the required dependencies to your project first.

One more thing: unless you're creating libraries that you want to test in other applications locally, you don't need to use mvn install or mvn clean install. mvn clean package will be sufficient.
 
ramesh merugu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Attribute name=main class value=com.middleoffice.webservices
Attribute name=class path value=all lib jars
this is ant values but in maven I have given only main class,how to give class path and all lib jars
Could you please someone write the code here,just few lines.
I am very confusing adding class path  jars.
Thanks in advance....
 
ramesh merugu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the class prefix is not correct for all jars that's why I am sending this
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37180
515
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ramesh merugu wrote:ut in maven I have given only main class,how to give class path and all lib jars

Maven automatically puts any dependencies that are not in the test scope into the classpath in the Manifest. So you are going to need to go through and add those entries from your Ant file t Maven dependencies. See JUnit in your Maven pom.xml for an example. Just exclude the scope tag.

ramesh merugu wrote:Could you please someone write the code here,just few lines.

As Rob noted, nobody here is going to write the file for you. We are here to help you learn. Also, it isn't a couple minutes of effort to migrate to Maven.

A good way to find the jar group id/artifact id/version for the XML is to search Maven Central. Click on the version number and you see the XML to copy for that jar:

 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:
ramesh merugu wrote:ut in maven I have given only main class,how to give class path and all lib jars

Maven automatically puts any dependencies that are not in the test scope into the classpath in the Manifest. So you are going to need to go through and add those entries from your Ant file t Maven dependencies. See JUnit in your Maven pom.xml for an example. Just exclude the scope tag.

Not out-of-the-box. I've checked several JAR files I've generated using Maven, and none of the have a Class-Path entry in the Manifest file. The same holds for libraries like Apache Commons BeanUtils.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37180
515
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob,
You're right. I've had  <addClasspath>true</addClasspath> in my parent POM so long that I forgot it wasn't the default.

Official docs/example here
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!