I'm trying to migrate my eclipse install from one workstation to another. I primarily work with Selenium, so I've copied my workspaces, imported the projects and imported the appropriate jars. However, I am still getting a lot of errors including some stating the import statements are failing to find certain packages.
Half of the errors cleared when I finished importing the last of the jars, but it seems like it's missing something. Basically guessing at this point, I right clicked my project and hit "build project", which cleared the import errors, but the rest of my code has errors indicating things are not imported correctly. I have a feeling the build path is still not configured correctly. Is there a way I can look at my old PC and see what files the import statement is looking for?
When you copied the files to another machine, and imported the project, some jars were not properly added to the classpath. So the compiler complained about not being able to find a class/package in an import statement. You can definitely have a look at the old work station, and look at the project imported jars. You can find those by:
Right click on the project in "Project Explorer", and select "Build Path > Configure Build Path".
This will give you an idea about what you are missing.
Alternatively, (if the libraries you are missing are third party), you can google the missing import statement, and get a clue in which jar (library) contains the jar, then download and add it to the classpath of the project.
Related
I spent the last 1,5 hour trying to make this simple tutorial work in IntelliJ IDEA, as you can see in this video.
When trying to run the code, I get the error:
/[...] -Dfile.encoding=UTF-8 src.HelloKt
Error: Could not find or load main class src.HelloKt
Caused by: java.lang.ClassNotFoundException: src.HelloKt
I have tried setting up SDK, invalidating cache, removing .idea and .gradle, rebuilding project, deleting the profile and adding it again. I tried those actions in different orders.
Here's a screenshot of the project:
It also complains Kotlin is not configured, but I have already configured it.
Here's the run configuration:
Here are the project settings:
Your Hello.kt file needs to be somewhere inside the src/main folder, probably in src/main/kotlin. This is different from the tutorial, because your project is using Gradle, and the one in the tutorial isn't. I think this is because newer versions of IntelliJ use Gradle by default for new projects, which wasn't the case when the tutorial was written.
The use of src/main/kotlin and src/test/kotlin as source code directories is a convention in Gradle (and Maven). When importing a Gradle project into IntelliJ, main becomes a module, and kotlin becomes a source folder within that module. The same goes for test. In your screenshots, the bold text and blue icons on main and test confirm that's how your project is set up. Files outside of those folders aren't treated as source files, which explains why your Hello.kt file isn't being compiled or recognised correctly.
It's likely that the default behaviour of IntelliJ when creating a new project has changed since this tutorial was written. In the tutorial, they select "Kotlin" as the project type and this creates a project that doesn't use Gradle. As a result, the project doesn't use the src/main/kotlin directory structure.
I can see from your video that you selected the same option, but on the next screen, IntelliJ still automatically selected Gradle as the build system for the new project. To match the project structure used in the tutorial, I think you would need to select "IntelliJ" as the build system.
In IntelliJ, I have a couple of separate applications which dont really depend on each other (and sometimes associated tests). Sometimes one of them has an error (cant find a package to import or so) and I really dont have time to fix it because I need to work on something else, I have no other choice but completely commenting out the offending file. Can I tell Intellij To please just ignore a certain file when I want to execute another application?
You should move the separate applications to separate modules. When you run an application, it will compile only the module containing this application and its dependencies, and will not compile the other modules.
Under "Project Settings" -> "Module", exclude the package you don't want to run:
So I'm working on a project that my friend had started. However, for some reason, after importing it from GitHub for the first time, there are hundreds of errors everywhere. It's a MineCraft plugin, and things such as 'Listener', 'EventHandler', '.getPlayer', are all getting 'Cannot resolve symbol'.
I took some screenshots, not sure if they will help in resolving any of this:
https://i.gyazo.com/81c21c5da19d6be1235870a4e213056d.png
https://gyazo.com/c692a04e3d598fe20de0ad79000cc409
Based on your screenshots, the project is referencing jars that IntelliJ can't find. In the project structure dialog, click on "problems" at the bottom and you should get a list of issues. Depending on the type of project you might need manually download the libraries.
I'm using the JDBC library in my IntelliJ project (mysql-connector-java-5.1.40-bin.jar)
I put it into a folder named lib and used right click > Add as Library to add it as a library. It worked fine.
Later, I zipped the project and moved it to another computer. After unzipping it and importing it in IntelliJ, it gave me the error SQLException: No suitable driver found for jdbc:mysql, which means that it couldn't find the library.
I looked through the file explorer in IntelliJ and it showed both the jar and XML file, and the XML file was pointing to the right location (jar://$PROJECT_DIR$/lib/mysql-connector-java-5.1.40-bin.jar).
I added the jar file as a library again and now it works. But how can I make it work without having to readd it each time?
Use Gradle (or Maven) for building and dependency management. IDEA should import a Gradle (or Maven) project just fine.
The problem was that I was overwriting the IntelliJ Module Library (.iml) file.
When you import a project to the same folder, IntelliJ asks you whether you want to overwrite or reuse the IML file. Since Overwrite was the default option, I selected it, but that caused it to forget what libraries it was using.
By choosing Reuse instead, it works perfectly.
I have a few import statements in my project that are displayed in RED. Intellij shows 'Cannot resolve symbol' errors, and I am not able to autocomplete these classes or their methods. However, when I run my project it runs perfectly fine. This is strange so much so, that lets say I have an import statement
import org.apache.velocity.app.Velocity
It cannot resolve the 'Velocity' class, even though when I do a ctrl+b selecting the 'app' package, it clearly shows the Velocity class:
I am lost in this and I am struggling to code like this. Any help will be appreciated.
Best Regards.
EDIT: In my project, some of the dependencies are also not resolved, although I refreshed my project multiple times. The exact same dependencies are resolved in my colleague's system, who is using the same code-branch and environment as me.
I can see that the unresolved dependencies lie inside the play.sbt package, but are still not resolved. Is there a compatibility issue between Intellij("15.0.2") and SBT("0.13.8" mentioned in build.properties of my app)?
Reimport project using option 'Import project from external model' and choose 'sbt'. In next window choose options like 'use auto-import' and download 'sources for SBT and plugins'.