I migrated my workspace from Eclipse to Intellij,
in Intellij I have a project build from two modules, the run configuration are set on one module but the main class is in the second one.
in Eclipse it works fine, but in Intellij I get "Error: Could not find or load main class [class name]".
I created a dependency in the project structure, and played a lot with the running configurations which didn't help.
Any ideas? does any one have an experience with this structure in intellij?
Adding more details:
I imported two eclipse projects to intellij - UI project which uses a jar from core project.
The two projects are depended, my goal is to run the UI project which use a jar from the core project, and be bale to debug in the IDE the code
from both projects.
In Eclipse it is done by adding the core project to the classpath in the debug configuration classpath before the UI (running) project.
In intellij I added runtime dependency between the projects which didn't work.
The project is running but from the Jar and not from the code of the second project - so I can't debug the code.
Add Run Configurations -
The main class is in the core project,
I tried to delete the created core jar from the classpath of the UI project and run it with module dependency, but it failed on main class not found error.
Ideas?
Thanks
OK got it - the Core jar should be in the dependencies in compile scope, as well as the module in provided scope, the main class can be from the core project and it works.
Thanks to all respondents
"The project is running but from the Jar and not from the code of the second project - so I can't debug the code."
I was also looking to do this. Your answer is not that clear. Here's what I did and it worked in my case,
Project Structure (Alt+Shift+S)
> Modules
> on the Sources tab for the module that has dependencies, look on the right side,
click the + Add Content Root, then add the src folder of the dependency project.
I was able to then put breakpoints in those src files and IntelliJ would step to them in debugging.
(Note you may see the warning "Alternative source available for the class ...")
Reference
From https://www.jetbrains.com/help/idea/creating-and-managing-modules.html,
"Modules normally have one content root. You can add more content roots. For example, this might be useful if pieces of your code are stored in different locations on your computer."
(see also How to debug a project in Intellij while setting the breakpoints in another project)
Related
I cloned the maven project to my local disk. The project has 3 modules as well as a parent project. i marked the 3 modules with the 3 colors-- the 4th, blue color is the project itself.
The project is running all fine on maven both on Eclipse and on command line.
When i do a mvn install on Eclipse, the project is built and all the tests are run successfully -- i see the good old BUILD SUCCESS report of maven on Eclipse console.
The problem is -- the modules are all messed up. (this "messed up" is the best way i can put it for now.) Eclipse doesn't recognize the dependencies between modules and gives checked errors to some of the code that use outside dependencies.
At one place-- lombok #Getter is used in one class. import lombok.Getter; is seen by the compiler-- no checked error to that. but eclipse doesn't recognize the getter declaration of lombok, say getField() for the field field. i know this because : a) in the class itself-- gives a warning that .. the private field field isn't used.
b) gives a checked error to getField() a reference from another class.
Thought this might be an interesting example to how the dependencies are "working". i'm guessing one dependency that lombok is using is intercepted somewhere along the way to give this inconsistency.
Following is the project root directory structure on disk. (the 3 colors are the 3 modules, have to hide the names for confidentiality):
the 3 modules are defined in the pom.xml as follows:
i see the following in Eclipse project explorer:
so in the Project explorer, the 2 modules/tests (green & yellow) that have java dir, i.e. src/main/java appear twice. the orange module has only src/main/resources and no src/main/java.
In the second occurrences of the modules in the project explorer (the image above), there are no dependencies of any kind, not even Java itself and hence all those red dots all around (compiler errors). The first occurrences of modules have Referenced Libraries and no Maven Dependencies:
How to fix this project so that i can code and run in Eclipse? Just to pin down-- project configuration is all fine and it runs successfully on maven. the problem is Eclipse's own settings on it.
so far i tried the following:
made the project faceted and added Java as the only one to its facets
imported as Maven project -- File > Import > Maven > Existing Maven Projects
ran mvn eclipse:eclipse on its pom.xml
Wasn't even seeing the Build path before these.
i'd appreciate the help-- wore me out.
everyone else on the project is IntelliJ developer-- no workspace to compare with.
i've seen Importing Maven project into Eclipse and some other useful discussions.
i'm not sure whether i should post .project, .settings and some other file contents also.
will do if necessary.
TIA.
Make sure to not only import the parent pom.xml, but also the Maven modules as projects into Eclipse. To do this in one go, use
File > Open Projects from File System... or
in the Git Repositories view right-click the root folder and choose Import Projects...
Make also sure Lombok has been installed into Eclipse, otherwise Eclipse's own incremental compiler would not generate e.g. getter and setter methods that are defined by Lombok annotations. See the Lombok documentation of how to install Lombok into Eclipse. If you have installed Lombok after importing the projects, it might be that you need to do a Project > Clean... or close and reopen again the projects (via the right-click menu).
I'm trying to replicate in Intellij something easily done in Eclipse.
I want to run this Main class from the mainProject (nevermind the errors due to the use of fictional names):
Now, the problem is I need to be able to import a configuration folder from another project, in order to run the Main class. This is easy in Eclipse:
But I don't know how to do this is Intellij. Ideas?
This is actually why I despise the Eclipse workspace. It lets developers cheat and use another project's source as a dependency of another project. This is a problem because this isn't how it works outside of the IDE.
What you need to do is create a jar of classes you depend on, then include that jar as a dependency of the project that depends on them. If you use dependency management and have a local repository (like nexus or artifactory) you can publish your jar to your local repository and then in your other project just include it in your pom.xml if you are using Maven or build.gradle if you are using Gradle.
If you are instead including libraries in your source folder, copy the jar to your project, then right click on the jar in IntelliJ and select "Add as Library...". You can also add a dependency through File->Project Structure->Modules->Dependencies tab. Add as Library is a shortcut to adding a library here and the dependency shows up here if you use Add as Library.
IntelliJ does let you import a module from another project, but again this is cheating because it will just confuse you down the road because it will only work from within the IDE, not running as a standalone application. (File->Project Structure->Modules->Plus (+) Sign->Import Module)
I know that there is a Git plugin for Eclipse ("Egit"), but I like to do Git stuff on the command line, and I like to code in Eclipse, so I want to keep them separate.
I cloned a Git repo (I don't think its important, but for good measure, it was https://github.com/spinscale/dropwizard-jobs.git). I then opened up Eclipse (Juno) and created a new Java project, and selected the root of the cloned repo as the base path to my project. Eclipse asked me if I wanted to associate the project with the Java facet, and I clicked 'OK'.
This project has a large dependency tree (if you like, check out its 4 POM files). I don't use Maven to build (I use Gradle) so I just ran a script that resolves the dependencies of these POMs into a directory, and then I created a lib directory in this Eclipse project and copied all the JARs into it. I then added all these JARs to the project's classpath.
I am now seeing 10 errors in the Problems view in Eclipse, and they're all similar errors:
The type ApplicationStartTestJob is already defined ApplicationStartTestJob.java /dropwizard-jobs/dropwizard-jobs-core/src/test/java/de/spinscale/dropwizard/jobs line 10 Java Problem
The type ApplicationStartTestJob is already defined ApplicationStartTestJob.java /dropwizard-jobs/dropwizard-jobs-guice/src/test/java/de/spinscale/dropwizard/jobs line 10 Java Problem
8 more all like this, etc.
Sure enough, when I expand the entire project, I see it has the following structure:
dropwizard-jobs/
dropwizard-jobs-core/
src/test/java/
de.spinscale.dropwizard.jobs
ApplicationStartTestJob.java
dropwizard-jobs-guice
src/test/java/
de.spinscale.dropwizard.jobs
ApplicationStartTestJob.java
dropwizard-jobs-spring
src/test/java/
de.spinscale.dropwizard.jobs
ApplicationStartTestJob.java
So it seems that the maintainers of this project like to rename their unit tests with the exact same package/class names, and for some reason, Eclipse sees them as all belonging inside the same package. To test this I renamed dropwizard-jobs-core/src/main/java/de.spinscale.dropwizard.jobs.ApplicationStartTest to something else, and did the same for dropwizard-jobs-guice/src/main/java/de.spinscale.dropwizard.jobs.ApplicationStartTest and sure enough, all the errors associated with ApplicationStartTest being already defined went away.
So my suspicion is confirmed: The intention of these subfolders (dropwizard-jobs-core, dropwizard-jobs-guice and dropwizard-jobs-spring) is that they are sub-projects with separate classpaths. Eclipse thinks all of these source folders are part of the same project, and so it is lumping all of their classes into the same classpath. Since each subproject uses the same unit test naming conventions (same package/class names for each subproject), Eclipse see multiple classes in the same package as having the same name.
OK, good! I figured out the problem. But what's the solution? Ideally I would be able to keep all of these inside the same project, but perhaps modify the .classpath file or do something similar that instruct Eclipse to keep the subprojects separated from a classpath perspective. Any ideas?
SImply download eclipse m2e plugin, then import the project(considering you have already checked-out at your workstation), and do spend sometime learning MAVEN commands. here you can find an pverview of maven parent project and modules. Maven parent pom vs modules pom
One possible solution would be to introduce maven, which allows to naturally define a parent project and sub-projects in a multi-module maven project.
You can actually test that configuration outside of Eclipse, and then use M2Eclipse in order to import parent and its dependencies, at the same time (as commented in this answer) in your Eclipse.
Actually, the M2Eclipse project itself has guice test project, which you can use as model for your own guive subproject, in the repo sonatype/m2eclipse-guice, with an adequate pom.xml.
I cloned a GitHub repo onto my disk an successfully built the project by:
ant clean-all resolve create-dot-classpath
within the projects root directory.
I assume this should also be possible from IntelliJ IDE but that fails by doing nothing at all - it simply states "All files are up-to-date" ... what I do is:
"Make module 'pentaho-kettle'"
"Compile module 'pentaho-kettle'"
I could use a hint where to look for a solution or what configuration is most likely missing.
As the project is a multi module project based on Ant and Ivy, you have to
import the project from sources
configure modules (like core, ui, the plugins, …) with the right directories for main and test sources and resources (they seem to overlap with java sources in that project)
setup the class path using an Ivy plugin (I recommend IvyIDEA), use the context menu on the ivy.xml file
and have luck to build. It will be some try and error!
You may also have a try importing from Eclipse as those .project and .classpath files are checked in. But than you also have to check the module directories, the import is more a partial guess and I worry that IntelliJ will not get any information about Ivy from the Eclipse setup.
I am getting a class not found exception for my Login Controller when I try to login to my application(It is a spring MVC Application). Before running the maven clean command the Application was running perfectly, I used maven clean and then again done a build using maven package command, suddenly it stopped working. I tried restarting the TomCat, re-deployed the application on TomCat, restarted the Eclipse IDE but nothing has worked so far.
Why this happens and what is the possible solution to this ??
Are you trying to run your project under Eclipse?
And does it generate source files?
If these are both true, you probably need to update the project config (select project or pom, right-click, Maven..Update..Project Configuration and Maven..Update..Project Dependencies).
The problem is that when Maven does a clean, it gets rid of the generated directories, which Eclipse observes and removes from your Build Path. But then when Maven rebuilds the directories, Eclipse doesn't notice it - you have to give it a hint.
Check your project for build errors and build path errors.
Make sure you've defined an M2_REPO classpath variable in Eclipse (Preferences - Java - Build Path - Classpath Variables).
If you're using the m2eclipe plugin, right-click your project and click on Maven - Update project configuration. That will configure an Eclipse build path for your project based on your pom dependencies.
If you're not using m2eclipse, execute mvn eclipse:clean eclipse:eclipse in your project folder. Then refresh your project in Eclipse.
What you haven't said is that you've checked and the missing class is in fact present.
A quick way to check is in the code editor SHIFT+CTRL+T and type the name of the missing class. Eclipse should not only show you the class if it exists, on highlighting the class, Eclipse should tell you which jar it is in.
Based on the info you have provided, I would say some dependecy in your POM has been removed by mistake or you need a newer version of some jar. If you find the class is not present, then you can figure out which jar you need by googling something like Maven 2 MyMissingClass jar that usually works for me.
Delete the .metadata folder in your eclipse workspace and then again open the workspace and import the required project.
This will solve your problem.
In .metadata folder it maintains the temporary copy of the project.
what worked in my case was simply removing the project from work space and importing it back again.
But I still don't know why it worked Vs why other things mentioned did not work (I tried updating dependencies in fact I removed all the dependencies from pom.xml and added everything again)