How to convert a Java project to a Maven project or similar

I am currently creating an application to compile several Java projects at a time for programming purposes. Since there are many different ways to submit Java projects (for example, an eclipse project, like a netbeans project, like a jar file), there is a plugin with something similar that you can easily import or use in a project that converts a Java project into a maven project, so that they can all be compiled in the same way, and then had to create functionality that allows the program to compile all the different types of Java projects?

If not for maven projects, is there any other way to accomplish what I'm trying to do?

+6
source share
6 answers

In my opinion, such a tool does not exist to somehow find out only a freestyle-style Java project. Maven is based on some proprietary conventions that are not necessarily shared. This is not only about where the Java files are located, but also where the resources are located (for example, they can be in the same directory as the Java files), where there are other assets (for example, WSDL files), what are these assets, how to process them and how use all this to successfully create the final package. I think there is no chance of having such a universal tool that can do this.

I think the best scenario that can be presented here is to find out some general assumptions about the projects you should build, for example. they can only contain Java sources and only regular resources. Then you can implement some script or program that scans such a simplified Java project to know where all these files are. And even then, what about dependencies? Should you scan Eclipse / Netbeans / IDEA files for them? It is very difficult to even create these assumptions that make projects simple enough to automatically obscure.

As I said, I really don't think you can do anything better than just ensure that projects are already managed by Maven.

+4
source

I'm not sure if I understood your question correctly, but most IDE programs (for example, Eclipse, Netbeans, etc.) have plugins for Maven in which you can "mavenize" the project from the right-click context menu in the " Customize "options.

+3
source

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

There is information in your IDE that such a plugin is needed. For example, eclipse gets its own files, such as .classpath, .settings / *. This, as far as I know, is a proprietary format, so it is not easy to read (although they are understandable to humans).

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

0
source

Using the Spring STS IDE (Spring Tool Suite), it is possible to convert the Java / Dynamic Web Project into a MAVEN project. I believe the same thing can be done through Eclipse as soon as you have the correct plugins

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

In the project, you will see pom.xml and other Mavenized functions.

0
source

I did the same for the Selenium project. Hope will be helpful

Please install TestNG and Maven on your system. Follow steps 1 to 8 and run the project

Step: 1 Right-click on Java Project, select "Configure Transition" in "Convert to Maven Project".

Follow Figure 1.1 and Figure 1.2

enter image description here

enter image description here

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

enter image description here

How to add cans,

Path: 1 Search in " https://mvnrepository.com/ " and add the repository

Path: 2 Add banks from the local system (select either path1 or path2 or both, if necessary) Create a folder (Say: lib) and put it 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> 

enter image description here

Step: 3 Convert the class to a test class enter image description here enter image description here

Step: 4 Modify test.xml.

Provide 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 should contain Annotation @Test

If not, add. See the program below.

 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 end, check all settings of TestNG, JDK

enter image description here

Step: 8 Run the project, click Maven Test

enter image description here

0
source

If you use Eclipse or Spring Tool Suite, right-click the project -> configure -> convert to maven project to convert your project to a maven project. You can check if the project contains a pom.xml file. If so, it has been successfully converted.

0
source

Source: https://habr.com/ru/post/917975/


All Articles