IntelliJ - No out folder - java

This might be a trivial question, but i can't solve it.
I have cloned a git repository, where the "out" folder was excluded (As it's supposed to), but i can't run the code.
It gives me an error called
"Error:java: /production/nameOfProject: does not exist"
I have narrowed the problem down to something with the project structure, and i have specified my "src" folder as the source folder, but i don't know what to do about the "paths"-section. Can't i get intelliJ to create the out folders automatically?
A temporary work around is to create the project again and import the modules, and here intelliJ creates the "out" folders, and the code compiles, but that can't be the right way.
This is how my intelliJ project structure modules look, if that helps: http://imgur.com/a/uc6Fa
Thank you.

I solved this by cloning the repository, and then i choose to "create a new project from existing sources", and picked the cloned repository. intellij even discovered the src-folders itself.

you can see how to build artifacts here:
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-application.html#package
When you make some new artifacts, then go into Build -> Build Artifacts...
IntelliJ will automatically generate out files.

Maybe just create new folder called "out" in project structure and mark it as excluded.
Have you created this from intellij vcs import?

Related

Eclipse referring old class files of Maven. Have to re-build the project everytime I make a single change

I am using Maven projects in my Eclipse workspace.
But, somehow Eclipse is referring the old .class files while running the program.
Hence, I have to re-build the complete project everytime I make any change to any java program.
I have tried executing maven commands like eclipse:clean & eclipse:eclipse.
But, they did not help.
My eclipse is also set to project - build automatically.
Is there a way I can tell Eclipse to refer to the current built .class files and not the previously built maven .class files.
Note: I am using Eclipse Mars
Thanks in advance.
I am afraid. There is no way to doing it automatically. Even if you find a way to do so. There isn't any guarantee that eclipse will build with new war.
Either you go for manual mvn clean install or use intellij idea it is very much statble. No build issue. Every time on your single save it will build new war file.
Posting answer to my question:
Sometimes the .project file of Eclipse gets corrupted. Easy solution is :
Delete the project from Eclipse.
Close Eclipse.
Go to your project's folder and delete ".settings, .project, .classpath, bin"
Open Eclipse again, and import your project once again.
This way it always works.

Eclipse:How to Detect a Project is Part of the Workspace

How can I make sure a project that is shown in my workspace is actually part of the workspace. Below, I will explain what happened so that you know why I'm asking this question.
I had checked out a project into my workspace, and then had configured it as a Maven project by selecting Configure->Convert to Maven Project; in most cases, when I do this, the project becomes part of the workspace. But in this case it hadn't. But I spent a few hours before realizing that I need to import the project in order for the workspace to recognize it as workspace project. So, I want to avoid this situation and be able to look at a flag or file or something that tells me if a project that is shown in the Eclipse window is actually a workspace project.
Thanks
I'm adding the following to make the problem more clear:
This is what I do; I have a workspace with a few projects (all Java/Maven project); everything works. Then I checkout another project from svn into the workspace; so, the folder of the new project is within the same workspace. I expected that as soon as I check out the new project into the workspace, and convert the new project into a Maven project, then the new project be recognized by Eclipse as one of the projects in the workspace. But that is not the case; I actually have to import it.
The project folder is there, and I can see it in the Project explorer. Nothing happens to it, but it is not used by the workspace. For example, if I add breakpoints to the Java files which are in the new project, they are not used. At this point, I use File->Import menu to import the project from the same folder that is already in the workspace, and bang, it starts working, and my breakpoints work.
Is my procedure for checking out a project from SVN into the workspace wrong? I want to fix my procedure to make sure this will never happen. Do you think that even though the new project is a subfolder of workspace, I should still need to import the project into the workspace?
I just noted another fact; this particular project that I'm importing is a Maven multi-module; could it be that the parent project is actually part of the workspace, but the modules inside it are not; therefore, just because it is a Maven multi-module, I need to import the sub-modules.
There are four ways to create a project in Eclipse:
create
Create in a default location (workspace folder on a filesystem)
Create in user-specified location (anywhere)
import
Project is referenced from workspace, untouched otherwise, location on a filesystem is unchanged
Project is copied into default location
You probably want to know if a project is located in workspace folder on filesystem. To do this, you can open project's properties and find location in resource node:
"... in order for the workspace to recognize it as a workspace project..." doesn't make any sense to me. I'm not exactly an eclipse expert, but a workspace is the set of directories in which you are working at one time in eclipse. There can be more than one workspace for eclipse on a given machine.
If you checked it out and it appeared in eclipse, then it was "in the workspace" afaik. Now, Maven tasks create and change files, and those changes do not automatically show up in the workspace -- you have to refresh the project, which essentially syncs the filespace with the workspace.
If that doesn't cover your case, then detail what you mean by "not in the workspace".

Intellij idea specify output folder for each source folder (like in eclipse)

I'm working with huge project which has almost hundred plugins which in turn has it's own folder. The issue is that this project was created in eclipse and for each plugin's source folder a corresponding output folder specified. I'm wondering if it is possible to do the same thing in intellij or I'm forced to use eclipse?
Just some screenshots to make thigs clearer:
In the project structure you can create an artifact for each of your library an specify an output directory.
Try File->Project Structure then in the Project Setting add new artifact and specify output directory

"Could not find or load main class" after removing Maven nature and files (pom.xml, target/) from an Eclipse Project

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 :-)

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

Categories

Resources