(HELIOS Eclipse, m2eclipse is installed from the update site)
I am creating a new web application: File->New->Other->Maven->Maven Project, Next, Next, then selected maven-archetype-webapp, added a Group Id and Artifact Id. Now in the newly created project I want to add a new java package: right click on , new -> package. Inserted package name and click on finish.
And I'm getting a new folder. Eclipse does not recognize this as a package.
What should I do to make Eclipse recognize that folder as a package?
Many tia,
DHR
The maven-archetype-webapp does not generate a src/main/java folder by default and if you want to add Java sources in your webapp, you need to create src/main/java yourself.
Once this directory has been created, right-click on your project and then use Maven > Update Project Configuration and it will get added as source directory. Then you'll be able to add sources.
Last thing, either use the maven-eclipse-plugin or use m2eclipse, not both, they are mutually exclusive.
It should work. You can mark the folder containing the package as "source folder" in eclipse, but only as a fast solution...
I usually work with eclipse wihout m2eclipse, and I run mvn eclipse:eclipse to generate the eclipse project. Maybe you can manually fix this running the command now (from eclipse with the plugin or from mvn directly).
Related
I imported a project from a git URI however in eclipse it shows as a files system instead of packages.
How can I fix this so the project can be exported as a jar?
You should be able to right click on the project itself and go down to "Add Project Natures" and select "Java". If it's already a Java Project, and it just misconfigured the build path, right click on src/main/java and do Build Path -> Use as Source Folder.
I would guess that 1) you are looking at the wrong root directory. That is looking at "src" instead of "Java Resources" (or something like that), and so not getting the packages you expect, or 2) The project doesn't have either the java or, more likely, the Maven builder loaded.
If your copy of Eclipse doesn't have a builder configured (like Maven (m2e)), then when you check out the project, it doesn't populate the way you expect.
I am trying to import the latest Log4j2 source in my eclipse and Eclipse is not detecting it as a project. it says 'No projects are found to import'. Is there a solution for this?
My goal is to make a jar out of this source. Can i do that without the need to importing it on my eclipse(maybe like a command line solution that can make a build for me)?
Eclipse is not detecting it as a project. it says 'No projects are found to import'. Is there a solution for this?
It's a maven project, so you should import Existing Maven Project
Can i do that without the need to importing it on my eclipse(maybe like a command line solution that can make a build for me)?
A simple jar command. You can see more at Using JAR Files: The Basics. A basic command example
> jar cf log4j-sources.jar * // the * is for all files in the current directory
Note: this will not build anything. Just put everything into a jar.
If you have maven you can ask maven to generate the Eclipse .project and .classpath files.
From the log4j2 top-level folder, run mvn eclipse:eclipse
Eclipse will now be able to recognize each module as a project.
After this, to import modules in Eclipse, take the following steps for each module:
File > New > Java Project - enter module name (e.g. log4j-api) for Project name, uncheck "Use default location" and click Browse... to navigate to the location of the log4j-api module. Then click Finish on the wizard.
I accidentally converted my project to Maven by going to Configure > Convert to Maven Project. Now I want to undo this. I read that I need to right click Maven > Disable Maven Nature and that worked fine. However I want to totally remove Maven, so I deleted the pom.xml and the target folder. When I try to run my code now, I get the error:
Error: Could not find or load main class
So what am I missing? How do I revert from a Maven project to a non-Maven project?
When you convert a Java project to a Maven project in Eclipse, the Maven Integration for Eclipse (m2eclipse) configures the Java incremental compiler to put the compiled class files in the same location as Maven would put them, i.e. target/classes.
So when you remove the Maven nature and delete the target folder, you now also have deleted the compiled class files and your project can no longer run. AFAIK, the incremental compiler doesn't detect when you remove its output files, so you need to trigger a rebuild by cleaning the project (Project > Clean...)
This will fix the problem that you can not launch your project, but may re-create a target folder. If you also want this to be "fixed", you can switch back to some other folder name for the binaries, e.g. bin, in the project's Java Build Path configuration on the Source tab.
Is it basically a Maven project, i.e., do you have and maintain it through a pom.xml? Then my suggestion is to delete the project in Eclipse but keep the files on the disk (i.e., it removes it from the workspace). Then, run a simple mvn eclipse:clean eclipse:eclipse which creates a simple Java project without the Maven nature based on the POM (so the libraries are linked and the source/output directories are set up correctly - this may solve your ClassNotFoundError).
If it's a simple Java project, I would advise deleting it from the workspace, removing the .classpath and .project files and importing it again with the Create a Java project with existing sources wizard.
Either way, make a backup of your project before you start doing anything :-)
I am working on a specific maven module. I have it imported into eclipse by m2eclipse plugin. The module uses our internal plugin to generate java files from some csv files. During install goal those files are being generated and put to target/generated-sources/folder_name.
Can you tell me how I can import these java files into eclipse so it stops showing me compilation errors saying that 'x' cannot be resolved to a type?
Now every module which uses those files has compilations errors in eclipse, everything works fine when I try to build from command line.
Thanks in advance.
UPDATE: Thanks a lot guys, I was trying similar solution but instead of adding source folder I was trying to add external classes :|
project -> properties -> java build path -> source -> add folder -> (search for target/generated-sources/folder_name, create it if deleted by maven) -> ok
now eclipse will only complain when you'll use mvn clean deleting target folder.
Eclipse refreshes file content on request, so any change made external to eclipse, eclipse doesn't know about that
You can make eclipse to use native hooks to detect external changes
preference > workspace > check refresh using native hooks
and add that directory to source path
You probably need to add the folder of the generated files as a Source folder in the project. Look in the Project Properties > Java Build Path > Source tab and add the folder.
I have several Maven projects converted into one Eclipse workspace. When I edit the code under Eclipse, I sometimes use CTRL+SHIFT+M combination of keys to automatically add imports to the classes from a project in my workspace. But somehow they are added like this:
import src.main.java.com.mycompany;
while to real package I wanted to import is com.mycompany.
This has to be some configuration in Eclipse to fix this but I'm confused. However, this issue is very annoying.
EDIT:
I've forgotten to mention that Eclipse files were generated using mvn eclipse:eclipse command.
Under Eclipse project seems to be configured properly. Its source folders set like this:
src/test/java
src/test/resources
src/main/java
src/main/resources
And everything under Eclipse works properly except the situation when I press CTRL+SHIFT+M keys
The standard source folder for Java projects is
./src
For imported maven projects, simply remove this folder from the list of source folders at the build path settigs. The correct source folder is
./src/main/java
In eclipse;
Remove the existing source folders first.
-right click -> menu -> build path -> remove from build path
then
Right click on the source folder.
build path -> use as source folder.
Seems like your settings are pointing to the parent of the source folder so src is recognized as package by eclipse.
It's because eclipse is not aware of the convention over configuration filestructure Maven is following. Install the M2Eclipse plugin and File > New > Other > Maven Project for new projects or for existing ones right click on your imported project on Package Explorer > Maven > Enable Dependency Management. Once successfully done, on the Package Explorer you would see your project nicely gathered following the Maven conventonal filestructure like src/main/java, src/main/resources, src/test/java and from then on you'll start seeing your package structure hierarchy like com.mysite.myproject..
First remove it. Then add it back using right click on package->build path->configure build path-> Source->Add Folder and add the entire /src/main/java tree
You've got the wrong source folders in your build path, and it's a wonder that anything works at all.
You can use either the maven-eclipse-plugin or M2Eclipse to automate getting this right, or you can manually fix the build path to call our your actual source folders, not their great-grandparents.
Non of the above worked for me. Finally I just changed the name of the scr folder to scr-java and this removed the package structure with scr as root package.