Eclipse git project messed up - java

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.

Related

Eclipse add external jars doesn't work to add them as Referenced libraries

I'm currently doing this tutorial on Hibernate over here http://www.javatpoint.com/example-to-create-hibernate-application-in-eclipse-ide and I downloaded the hibernate.zip and oracle.jar files, tried to add them to the project through right clicking on the project -> build path -> configure build path -> add external jars and selecting the jars, but they are not getting imported in a "Referenced library", they just appear as stand alone .jar files that don't to anything and can't be referenced to.
How can I make them "go" into the Referenced Libraries? That folder isn't even created when I import the jar files.
Thanks!
You should use Maven for handling your dependencies and let Eclipse & Maven together take care of downloading and organizing your dependencies. You won't even need to download the jar files manually anymore.
This is the basic usage of Maven with Eclipse:
http://www.tech-recipes.com/rx/39279/create-a-new-maven-project-in-eclipse/
In case you're totally new to Maven, i'm happy to provide further help via comments.
I suppose your Eclipse perspective is selected "Resource", not "Java" or "Java EE".
After you change the perspective to "Java", you will see the Referenced Libraries.
Check this Option : Right click Project >> Show In >> Project Explorer

Creating a jar file in IntelliJ 12.1.4?

I have seen several of this question asked here, but none have fully been answered to my necessity. I have a file I want to create a jar file with so I can simply place it on my desktop and run it. I think I understand the process up to using Process Structure, then I am lost.
Basically, you can generate an artifact in IntelliJ from the build menu -> build artifact.
Dependending on your project, possible artifacts may be found automatically or not (if you use a "build tool" like maven, ant or gradle).
In case of a build tool, check its documentation to find how to generate a jar file from it.
If you're using a pure IntelliJ project, select your project root and hit F4, it will open its settings. In Artifacts, you'll have to add a new jar (the green + at the top of the window). Select "From modules and dependencies...". Then, you'll have to select the module to use and its main class. It should be enough. Then, you'll just have to build the needed artifact. The jar file will be generated in the folder defined in the configuration (Project settings->Project, Project compiler output in case of a single module, otherwise it will be generated in the module's folder)
When you're looking for a feature in IntelliJ, don't forget to use ctrl+shift+A to search it by its name.
Hope it helps

eclipse doesn't see java file generated during installation of maven module

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.

Wrong package name when using automatically added imports in Eclipse

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.

eclipse does not recognize package

(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).

Categories

Resources