What is the equivalent of the retired mvn eclipse:eclipse in m2e? - java

The Apache Maven Eclipse Plugin is retired. What is the equivalent command line or in Eclipse UI for:
mvn eclipse:eclipse
that generates the files that a project requires to be seen as a Java project in Eclipse?

The eclipse goal of the maven-eclipse-plugin would actually:
generates the Eclipse configuration files.
Which basically means .project, .classpath and the .settings folder.
These folders and procedure is handled by the Import action, where you can actually specify to import an existing project as a Maven project:
Right click on the Projects view > Import > Import... The procedure will properly create the aforementioned files and configure Eclipse accordingly.
However, shall you already have the project imported (in that case files would already exist), you can convert the existing project to Maven via the Configure action:
A right click on the concerned project > Configure > Convert to Maven Nature would then modify the existing files and settings to recognize the Maven build (mostly adding the org.eclipse.m2e.core.maven2Nature nature and org.eclipse.m2e.core.maven2Builder information to the existing .project file).

Related

why do we need to build java code before importing to eclipse for methods autosuggestion

I have a fundamental question, but something which bothers me a lot. We sync code from perforce in my company. and then we are taught to build the code compatible to eclipse. Then we import the code in eclipse as existing project. Then when we hit ctrl-space from an object, we get suggestions of methods.
My question is: Why do we need to build the code for suggestions of methods? . After syncing from perforce, what I have is still an existing java project (right?). So eclipse should be smart enough to be able to index and find out from source code, the methods, when I hit ctrl-space on an object?.
Why do I need to build? What purpose the build serves?
The code does not have to be built, but to be able to import a directory as project via File > Import...: General > Existing Projects into Workspace into Eclipse, at least the file .project must exist.
There are several ways to import, for example, a Maven project:
Execute mvn eclipse:eclipse on the command line and in Eclipse do File > Import...: General > Existing Projects into Workspace
File > Import...: Maven > Existing Maven Projects without a command line call uses by default the in Eclipse embedded Maven
File > Open Projects from File System... (or in Git Repositories view right-click + Import Projects...) detects not only Maven projects but also plain Java projects and automatically configures them accordingly.
In all three ways the following files are created, which are required in Eclipse for the Java content assist (Ctrl+Space) to work:
.project - says whether it is e. g. a Java, a PHP or a C/C++ project (to be more precise, the project name, builders and natures are specified here, e. g. the project folder icon of a Java Maven project will be decorated with a M and a J based on the Java and Maven project natures)
.classpath - tells Eclipse where the source and output folders are and which JARs should be added to the classpath (in Maven projects, the JARs are not listed, but it refers to the Maven dependencies which are computed from the pom.xml file)
.settings/org.eclipse.jdt.core.prefs - contains Java compiler and optional formatter settings (e. g. which Java version; which problems should be ignored or shown as infos, as warnings or as errors, etc.)
With Eclipse Oomph you can automate even more: you select a project and based on a project-specific configuration, for example, a Git repository is automatically cloned and plug-ins necessary to edit the project are automatically installed and configured.
Eclipse uses relfection for the suggestion, it can be possible only if the .class file generated

How do I properly organize jars into one folder in Eclipse?

I used Maven to generate a Jersey project from command line, and I also used mvn eclipse:eclipse so that I can import my project to eclipse.
After I opened the project from Eclipse I see all the jars were in the root folder, how do I create a folder or package so that I can move all these jars into it?
Don't use mvn eclipse:eclipse.
Just do File -> Import -> Maven -> Existing Maven projects and browse the folder where your pom.xml is and Eclipse will organize everything for you.
It looks like you aren't using Maven eclipse integration - m2eclipse. You shouldn't have to install it, it comes already with more recent versions of Eclipse, though follow the instructions in that link if you don't yet have it.
If you just generated the project, try deleting it and then generating it again inside eclipse with New -> Other -> Maven Project. If you have a lot of code written already, instead right click on the project and do Configure -> Convert to Maven Project. Once you've done that, you may have to do Maven -> Update Project project to straighten out your jars, and possibly remove them manually with Build Path -> Configure Build Path.
However, I recommend creating the project from within Eclipse, if possible.
Addendum: #cahen's answer is also correct; don't use mvn eclipse:eclipse.

How to import existing Ant build.xml into IntelliJ IDEA

I have an existing project that uses an Ant build.xml file to maintain the location of dependency jars.
In Eclipse it's very easy to import from an existing Ant file. I have searched online and looked through all of the "new project" options in IntelliJ but cannot figure out how to do this.
The closest thing I've done is File > New > Project from Existing Sources. But my whole project is full of errors because it didn't use the build.xml to include the jars.
Intellij supports Ant projects via built in Ant plugin which is included by default in IDE.
To check if it is enabled go to Settings > Plugins > Ant
After enabling plugin, you can use build.xml from View > Tool Windows > Ant Build
You should then have option(+) of importing your build.xml file.
Import the project "from existing sources" without choosing any build tool (ant is not on the list, only maven, sbt, etc...). Then after completing the import wizard, in the project files view, right click ant's build.xml file, and choose the option relating to ant which is hiding at the bottom of the menu.
You should use File > New > Module instead of File > New > Project from Existing Sources for Ant project. You also need to set your Content root and Module file location to your current Ant project directory.
You may also need to set right path to project output in Project Structure > Use module compile output path and set proper content route in Project Structure > Sources
Please, follow the steps below if you use the IntellIj:
Check the Ant plugin for the project.
select the build.xml file and add as the Ant build file
Use the side button to deploy the project

Can I convert eclipse source folders into packages?

I've forked a Github project, used Eclipse to clone it locally, and imported that as a general project into Eclipse.
The accompanying .project file is an Eclipse .project file with the proper "nature" and "buildCommand" xml tags.
So it seems like a valid Eclipse project. However, I'm unable to specify a run configuration or configure the build path.
When I select the Build Path popup menu item, it says "no actions available" in grayed out text. When I select "Run/Run As" from the main menu,
it shows (none applicable). I'm wondering if the problem is that the project imported completely as source folders:
There are no packages to speak of. I created another project from scratch, and created the proper source folders and packages as needed
to match the package statements in the source code. After manually importing the source from the git repo, I can build and run that project.
If the lack of packages is indeed the problem, is there a quick way in Eclipse to convert source folders to packages?
What you did is you have probably cloned the repo in Eclipse and then Imported this project through a New Project Wizard, because in GitHub there is no existing .project (and no .classpath) files.
The "New Project Wizard" will create a set of defaults for a java project (I suspect that you selected just that), but is anaware of Maven structure, so all source folders will not be recognized and you will end up having to define them on your own. Worse, you will be unaware of any special parts of the Maven build that might be configured within pom.xml.
Because this project uses Maven for building, it would be better to use M2Eclipse while importing it. Install it using Help->Install new software.
Then there are a couple of steps required to make it use all Eclipse features.
Keep your cloned copy of the repository or clone again if you want to start from scratch. Then use File->Import feature to import a maven project into the workspace. Select Exisiting Maven Projects and point to the directory containing pom.xml file in the cloned repo. This will use Maven integration in Eclipse to generate .project and .classpath files based on pom.xml contents, so you will be able to more closely mimic Maven build in Eclipse. All source folders should be properly discovered this way. Eclipse might want to install some additional integrations for Maven features that this particular project uses. Let it, if that is the case.
Now, you will have the project operational and compiling in Eclipse, but it will not be aware that it is managed by Git... This is because M2Eclipse and Git Team provider are not integrated (at least they weren't when I last checked). In order to be able to commit to the repository in Eclipse, remove the project from workspace, but without deleting contents. Then, import from Repository view using Import Projects/Import exsisting Eclipse projects. Since necessary .project file is already generated, Eclipse will autodiscover the project and will use the right configuration prepared earlier by M2Eclipse.
In the end you will have a properly configured Maven project with Git as a team provider for it.
If this is a project meant to be built by Maven that contains a pom.xml file, install M2E before importing the project from your local cloned repository. It will handle this.
Right click at root of project select properties, in the sources tab add the folder "src/main/java" as source folder
Other way is to configure facet as java

what is the difference between maven-archetype-webapp and eclipse dynamic web project

why do I need to apply: mvn eclipse:eclipse command?
are they equivalent to application container/server?
Is there a file for which customizing is necessary besides web.xml?
when you create a web project using maven, like maven-archetype-webapp. It creates the folder structure as recommend by Maven for a webapp like shown here .
Now when you try to import these folders in Eclipse, it still would look like folders but eclipse cannot understand the nature of these folders. Eclipse relates folders and contents within them to an Eclipse dynamic web project only through its .project , .settings files
So in order for your maven project to be understood by Eclipse, you run the goal mvn eclipse:eclipse. After executing this goal, maven generates the .project, .settings files necessary for eclipse to understand the project as Web project.
This is however optional. You can still import the project as Maven projects within eclipse and continue to use them but you cant rely on Eclipse's features like clean/ build / build automatically.
Though I use eclipse, I dont rely on Eclipse's build feature. I have installed Maven eclipse plugin and that allows me to run maven goals and commands within Eclipse which is as good as running Eclipse's build feature. Hope this helps.

Categories