How to convert java project to Maven project or similar

I am currently creating an application for compiling multiple java projects in one go for programming assignments. As there are many different ways to submit java projects(e.g. as eclipse project, as netbeans project, as jar file) is there a plugin of something similar that you can easily import or use in a project that will convert a java project to a maven project so they can all be compiled in the same way rather then having to create functionality to allow the program to compile all different types of java projects?

If not to maven projects, is there another way to accomplish what i am trying to do?

Answers


In my opinion, there is no such tool to mavenize just freestyle Java project just like that. Maven is based on some own conventions that are not necessarily common. It's not just about where Java files are, but also where the resources are (e.g. they can be at a same directory with Java files), where other assets are (e.g. WSDL files), what are these assets, how to handle them and how to use all this stuff to successfully build final package. I think there's no chance to have such universal tool that can do this.

I think the best scenario one can imagine here is to figure out some common assumptions about projects you have to build, e.g. they can only contain Java sources and just regular resources. Then you can implement some script or program that scans such simplified Java project to know where all these files are. And even then, what about dependencies? Should you scan Eclipse/Netbeans/IDEA specific files for them? It's really hard to even create these assumptions that make projects simple enough to auto-mavenize.

As I said, I really don't believe you can do something better than just enforce projects to be already Maven-managed.


I am not sure if I understood your question exactly, but most IDE software (e.g. Eclipse, Netbeans etc) have plugins for Maven, in which you can "mavenize" a project from the right-click contextual menu under the "Configure" options.


As posdef said, Eclipse (with m2eclipse or iam) and IntelliJ can do that :

Your IDE have the information that such a plugin would needs. For instance, eclipse get its own files like .classpath, .settings/*. This is, as far as i know, proprietary format, so it's not easy to parse (although they are human readable).

I'm not sure you'll find what you are looking for.


Using Spring STS IDE (Spring Tool Suite), there is option to Convert Java/Dynamic Web Project into MAVEN Project. I believe the same you can accomplish through Eclipse as well once you have proper plug-ins

Right click on your Web project --> Configure --> Convert to Maven Project.

You will see pom.xml and other Mavenized features into your project.


I have done the same for Selenium Project. Hope will be useful

Please install TestNG and Maven in your system. Follow all Step 1 to Step 8, and Run your Project

Step:1 Right click on Java Project, click on Configure navigate to Convert to Maven Project.

Follow, figure 1.1 and figure 1.2

Step:2 Add all dependencies (required jars and plugins surefire-plugin for testing.xml)

How to add jars,

Way:1 Search in “https://mvnrepository.com/ “and add the repository

Way:2 Add jars from Local system (Chose either way1 or way2 or both if needed) Create a folder (Say: lib) and place in the same directory

<dependency>
<groupId>selenium-server-standalone-3.3.1</groupId>
<artifactId>selenium-server-standalone-3.3.1</artifactId>
<version>3.3.1</version>
<systemPath>${basedir}/lib/selenium-server-standalone-3.3.1.jar</systemPath>
<scope>system</scope>
</dependency>   

Step:3 Convert your class to testing class

Step:4 Edit testing.xml.

Provide the class Name save it

<suite name="Suite">
<test name="Test">
<classes>
<class name="test.java.CurseraTesting" />
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->

Step:5 Your class must contain Annotation @Test

If not, please add. See the below program,

package test.java;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
public class URL {
@Test
public void openUrl() throws InterruptedException{
System.setProperty("webdriver.chrome.driver","C:\\Users\\shivendra.pandey\\Downloads\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.co.in/?gfe_rd=cr&ei=EjlbWbnFPOSK8QeylZ7ACw");
Thread.sleep(1000);
driver.manage().window().maximize();
driver.findElement(By.xpath("//*[@title='Search']")).sendKeys("sanfoundry");
Thread.sleep(1000);
driver.close();
}
}

Step:7 At the last verify all the setup’s TestNG, JDK

Step:8 Run your Project, click on Maven Test


If you are using Eclipse or Spring Tool Suite, right click on the project -> configure -> convert to maven project should convert your project to a maven project. You can check whether the project contains a pom.xml file. If yes then it is successfully converted.


Need Your Help

gwtupload input type costum

java css gwt gwtupload

I using the gwtupload libary to change the upload view of my application. I want to implement basically the same as in this example "Single uploader using a customizable button...". Therefore I'm h...

Insert on duplicate key update always updates all values

php mysql sql

I'm trying to update a row or insert a new one if it exists. If there's an UPDATE I just like to update the "updated" column with the current timestamp otherwise "added" AND "updated" get the same ...