Problems with IntelliJ at cloning repo from github - java

I am new to github. I tried to clone a repo and then pull the files on my computer. All the other team members did the same thing and it worked for them. When i open the project with Intellij all the .java files look like this:
files
It also says that my SDK isn't set.
I tried to set my SDK, and also i tried to set the java directory as 'sources root' because someone said that is a problem with the project structure.
These problems disappeared but then IntelliJ didn't recognize that my project is a maven project so i had to add manually the file pom.xml and refresh maven.
Then this problem disappeared but i had another:
"Cannot start compilation: the output path is not specified for module 'cmsiss'.
Specify the output path in Configure Project."
I tried to set it from project structure but now I have this error:output error
Please help.

Open maven project using pom.xml file. File->Open->pom.xml
Sources should be pointed to project root, not java directory.
Give these a try.

The usual steps that I follow to open the project:
git clone <github clone url>
Open the project in intelli J using
File<Open
and browse to open the root of the project.
This should work fine but if it does not, a few more things you can try:
Try making the project root as a maven module
You can open the Project Structure to make sure you have Java SDK set up properly. It should show the java version you are using there.
Worst case, that is if nothing else works and if the project is not too big, just create a new maven project and make sure it runs, then add all the project files.

I pulled the project again and started from zero. I specified the SDK and then I opened the Maven project window and added a maven project (selected the pom.xml file) and refreshed it. Maven did it's job and created the project structure and all the stuff I've tried to do manually and finally worked!

Related

Can I add Selenium jar library and link it with the code in Github?

I am newbie to GitHub and I made an open source project.
I have linked my GitHub project with eclipse.
The code is commited, but it is dependent on Selenium jar file (which is not commited/available on GitHub).
In Eclipse I have added Selenium jar in Java Build Path so my code doesn't give compilation errors.
Since I am newbie to GitHub I don't know how to add jar in build path of GitHub(If there is need to do that).
My questions are:
Is jar/libraries need to be added on build path of GitHub for project ? If yes then how to do it ?
How can we check code compilation errors on GitHub ?
For Question : 1
In Github first you have to check the gitignore file of your project
For further reference please go through the following links :
https://git-scm.com/docs/gitignore
https://github.com/github/gitignore/blob/master/Java.gitignore
Please remove .*jar references from the git ignore file
Keep your third party libraries in your Eclipse Project root directory.
In Eclipse build path Click on Add Jars and select the jars from your project root.
This adds a relative classpath for the jars. So even if you switch to a new machine also you don't need worry about classpath issues just git pull and run the tests.
For Question 2
Github can't check Java compilation errors.
Github is a Version Control Management and Collaboration tool.

build error after importing maven projects

I cloned one of the open source git repositories and was trying to import it as maven project in eclipse. After I imported everything as a maven project, whole package is getting messed up. See the below error:
How can I fix this issue so that I can build it on my local box? I cloned the same git repository locally on my desktop.
I am using eclipse version:
Eclipse IDE for Java Developers
Version: Luna Service Release 1a (4.4.1)
Build id: 20150109-0600
Steps I have tried already:
I have already tried maven->update project.
I have also tried removing and adding it again.
I tried mvn clean install both on command line and eclipse, they are successful as well.
Can anyone help me with this? If needed, you can also clone it and try importing it to see whether it works for you or not.
The root of your problem is that the build section of the pom.xml for that project specifies:
<sourceDirectory>./src</sourceDirectory>
Eclipse uses the sourceDirectory tag to tell it where the root of the main sources are. If you change that to ./src/main/java, then right-click on the project > Maven > Update Project... and click Ok (I had to do this twice) it will fix the Eclipse classpath so Eclipse can build the project. You can then revert the pom back to the head revision and so long as you don't run Update Project again it should continue to build.
I'm unclear on why that project specifies a non-standard source directory but uses the standard Maven layout, but this should at least get you into a working state within Eclipse.

imported maven project does not appear as java project. Shows folders

I checked out the existing project source code from SVN to a folder in my system.
Then I opened eclipse. Import Project-> Existing Maven Project.
It imported without issues. However, Project Explorer shows it as just folders instead of packages. (Like when we create a package and then add classes to it, it shows a different icon for package root). I opened Navigator and Package Explorer as well. But they are showing them as folders as well.
I tried:
mvn eclipse:clean
mvn eclipse:eclipse
on the root of the project. But it did not help.
Can anyone help on this one?
My folder structure:
ecs->
ecs-ejb->
src/java/main/com/xxx
pom.xml
ecs->ear->
src/java/main/com/xxx
pom.xml
pom.xml
Try to:
Right click the project->Configure->Convert to Maven Project
---- Edit ----
If this doesnt work, it is likely that someone checked in their environment files into your SVN. If they checked in:
.project
.classpath
.settings/
They could be conflicting with your environment (different settings/plugins/versions of eclipse...). Try dropping your project, deleting the folder/files, then remove these files from SVN, and repeat your initial process. All of these files/folders will get generated during the import to eclipse.
---- Edit 2 ----
Per your recent edit to the question, you have a multi-module project. If you only did this on the parent project, then there is no source folder. So you wouldn't see it. You should:
File->Import...
Choose Existing Maven Projects, Next
Set the Root Directory to ecs/ecs-ejb, Finish
Repeat for all other modules.
In eclipse, each module of a multi-module maven project needs its own eclipse project.
Right click the project->Configure->Convert to Faceted Form
This solution worked for me
Possibility is Module doesn't have .classpath.
Kindly right click on Module and Change Project fact as Java.
else
If you are using command Prompt.
1. mvn eclipse:clean
2. mvn eclipse:eclipse
else
Delete Project from Eclipse don't delete content from disk. remove .classpath and .project
Re-import as maven existing Project
Right Click->Maven->Update Project.
Above works perfectly fine for Eclipse Juno and solves the problem.
You just need to change the nature of the project.
For MAC->
-> Right click on project
-> Properties -> Check Project Natures
-> Then add or remove accordingly if you are having a maven project then add Maven, add Java
I had the same problem. I tried a lot of things that I read on internet but the only way that I found to solve my problem was exclude all of my workspace files (.metadata folder) and create another one.
After that, I imported a existing maven project and all my problems are gone.
I also faced a similar issue. I resolved it by downloading the correct apache maven plugins in the maven repository org / apache/ Maven/ plugins. IN my case, everything was working fine earlier and I had deleted .m2 repository completely. After that I started getting these issues with same iDE and newer IDE versions as well. The pom.xml showed error related to lifecycle mappings. On downloading the correct plugin, the workspace worked fine.
Delete the metadata folder. Checkout again but select "Checkout as a project configured using the New Project Wizard" instead of "Checkout as a project in the workspace".
Then a New Project wizard will open, type maven there and select "Checkout Maven Projects from SCM" preferably or "Maven Project". It should work. Remember this step should be performed for Maven Projects only. For normal Projects just select Java Project or whatever relevant type Eclipse project it is.
Check and make sure you have eclipse pointing at a Java JDK directory instead of a Java JRE directory.
I had just installed eclipse and only the JRE was in the settings. I added the JDK path, changed it to the default and clicked on Maven -> Update project. Then the packages appeared in Package Explorer.
The hint that helped me figure this out is that when I tried to use the refactor to rename a class, it wouldn't do it, complaining that it wasn't a JDK.
Instead of importing as Existing Maven Project, follow below steps
I assume that your folder has pom.xml, src/main and src/test.
Step 1: Right click > Create New > Java Project > Chose the project folder has pom.xml
Step 2: Right Click on Project > Configure > Convert to Maven project
I got it working using Proyect --> Properties --> Project Facets
In my case was a web project so I checked Java and Dynamic Web Module
Try right click on project, Maven->Update Project... (or similar, the link name changes depending on version)
This works for me when adding new folders, but I have not encountered the problem when importing a project.
Right click the project, then click Configure -> Convert to Maven Project. If the packages still display as ordinary folders, then right click on the folder one level up (the one that is supposed to be the source folder), then click Build Path -> Use as a source folder.
Here is my solution please close the Project Explorer at the left top and open again.
(or)
1). Right Click on your miscellaneous project and choose project Explorer if available.
Adding projects to working sets should help
try it ->
right click the project -> Maven -> Assign Working Sets... -> Add projects to working sets

Compiler error "archive for required library could not be read" - Spring Tool Suite

I am starting to configure my development environment and I am using Spring Tool Suite 2.8.1 along with m2E 1.01.
As far as I can tell, since this is a Maven Project (my first), my Maven POM is dictating (along with m2E smarts) my project build configuration and dependencies.
What I would like to know is why my IDE is displaying Java Build Problems that read "Archive required for library library/path/somejar.jar cannot be read or is not a valid zip file" when I can see the jars in my .m2 repository?
All the errors pertained to commons-logging:1.1.1 which I excluded in my parent-pom. This was a transistive dependancy via spring-context-support:3.0.5. I excluded that library from my build and now the errors pertain to the spring-context-support library.
I have attached a screenshot to illustrate.
Indeed IDEs often cache the local repository (Eclipse does something similar, and I have to relaunch Eclipse).
One ugly maven behavior you might encounter is that if you declare a dependency before you actually install it, maven will create an empty version of the missing dependency (folder with metadata but no jar), and you will have to manually clean your .m2 repository.
Third, an installed archive (jar...) can get corrupted, so try to open it with any archive tool (7zip...) to test it, and delete the whole folder if the archive is corrupted.
In my case I had to manually delete all the files in .m2\repository folder and then open command prompt and run mvn -install command in my project directory.
I was using Eclipse as IDE and I was getting very same error. I had to do Project->Maven->Update Project. Select all the checkboxes below except "offline" esp. the one "Force update of snapshots/releases" and click OK. Did the Clean Build for the Project again.
Delete corrupted files from your local .m2 repository and Ctrl+F5 (Update Maven Project) in Eclipse/STS. It'll download and install these files.
This worked for me.
Close Eclipse
Delete ./m2/repository
Open Eclipse, it will automatically download all the jars
If still problem remains, then right click project > Maven > Update Project... > Check 'Force Update of Snapshots/Releases'
Below Steps resolved my issue.
Go to ./m2/repository folder.
Go to respective archive error folder.
Verify any zip file is exist.
delete error name folder.
Now come to Eclipse Project - Right Click - Maven - > Update Project.
Above trick works for me.
For Googlers:
In my case I had accidentally manually added a Java class to the build path while poking around Eclipse. By taking a look at the 'Configure Build Path...> Libraries I removed the culprit class and now only have the
JRE System Library
Maven Dependencies
and nothing is complaining.
In my case I tried all the tips suggested but the error remained. I solved changing with a more recent version and writing that in the pom.xml. After this everything is now ok.
I deleted the local maven repository.
Then just rightclick the project -> Maven -> Update Project...
Select all concerned projects and click OK.
I was facing the same problem with my project.
My project was not able to find this archive: -
C:\Users\rakeshnarang\.m2\repository\org\hibernate\hibernate-core\5.3.7.Final
I went to this directory and deleted this folder.
Went back to eclipse and hit ALT + F5 to update the project.
The jar file was downloaded again and the problem was solved.
You should try this.
This happens when Eclipse screws up. To fix it, delete all the files in:
workspace/.metadata/.plugins/org.eclipse.jdt.core
Remove maven dependenices from build path
I faced this problem. I had "Archive for required library spring-boot-devtools cannot be read or is not a valid ZIP file" and the solution was like that:-
1- determine the dependencies names that have problems(for may case it is spring-boot-devtools).
2- close eclipse.
3- search in your .m2 file on these dependencies(by name).
4- delete these folders.
5- reopen eclipse and let maven rebuild your dependencies again.
Ok, I had the same problem with STS on a mac and solved it by deleting all the files in repository folder and from the STS IDE click on the project and then Maven -> Update project. Give it a couple of minutes to download all the dependencies and the problem is solved.
I face with the same issue. I deleted the local repository and relaunched the ID. It worked fine .
Just had this problem on Indigo SR2. It popped up after I removed a superfluous jar from the classpath (build path). Restarting Eclipse didn't help. Added back the jar to the build path...error went away. Removed the jar once again, and this time I was spared from another complaint.
none of the solutions above helped my problem. I've resolved it by deleting all files in {projectworkspace}/.metadata folder AND in {location}/.m2 folder and let eclipse download every single thing again. Hope this helps someone, cheers!
When I got an error saying "archive for required library could not be read," I solved it by removing the JARS in question from the Build Path of the project, and then using "Add External Jars" to add them back in again (navigating to the same folder that they were in). Using the "Add Jars" button wouldn't work, and the error would still be there. But using "Add External Jars" worked.
This could be due to you have added spring-licence.txt file to your web app libraries.
I had similar issue and resolved after removing that text file. In libraries it will expect jar file only.
Alternatively, below commands also worked for me:
mvn -s settings.xml eclipse:clean
mvn -s settings.xml eclipse:eclipse
In case of VSCode, follow the below steps:
Navigate to the respective folder that contains the corrupted jar
Delete just the jar
mvn clean
mvn compile
That worked for me.
Read the issue in Problems section,identify which dependency not able to read, then go the maven repository .m2\repository ->
1)check the dependencies and delete it from the folder
2)go to STS/Eclipse -> click on maven -> update project ->select the force update of snapshots/releases and click on ok.
or
delete the dependencies from the .m2/repository and rebuild the maven --> update the maven project
In my case, I just had to remove the following 2 lines from proguard.cfg:
-keep class android.support.v4.** { * ; }
-dontwarn android.support.v4.**
Yes, I know that the question refers to the Spring Tool Suite but:
Spring Tool Suite is based on Eclipse (the IDE I am currently using for ADT).
Proguard is a Java obfuscator that can be used for any project, not just Android
I tried all the suggested answers and tips in the thread and none worked for me, until I removed the references to said libs.
I hope this helps someone.
Delete your C:\Users\PC\.m2** folder
and update maven project

Problem loading resources while running in Eclipse

I'm working on a swing project, using maven2 (from command-line) and eclipse (without maven integration). So, I generate the eclipse project through maven eclipse plugin (mvn eclipse:eclipse), import it inside eclipse, and do all my work.
My problem is: when I run my app in eclipse (as a Java Application), I can't find none of the resources that are in my src directory. Digging for information on my problem, I get into this answer from another question. So, I compared the output from the following instructions:
MyClass.class.getResource("/").getPath();
MyClass.class.getProtectionDomain().getCodeSource().getLocation().toString();
Those gave me the following outputs, respectively:
${workspace_loc}/${my_project}/target/test-classes/
file:/${workspace_loc}/${my_project}/target/classes/
Checking the above locations, I could see that the former is empty, while the other one contained all my compiled classes and resources. So, I came to the conclusion that the classloader is looking for my resources in the wrong place. So, I think I have three questions:
Is my understanding correct?
If so, how it does to find the classes it is loading?
How do I solve this?
UPDATE: I've changed my code, so instead of invoking MyClass.class.getResource(...) or MyClass.class.getResourceAsStream(...), I'm now using ClassLoader.getSystemResource(...) and ClassLoader.getSystemResourceAsStream(...). In this way, everything is working fine in eclipse. I just don't know exactly why. Any hint on this?
Two possibles cases for me :
You are using eclipse to compile your project. Then eclipse is configured to exclude (or not include) resources in the src folder. You can set it in Project/Properties/Java Build Path/Source. Then you expend your src folder, and ensure you have something like "Included All", "Excluded None".
You run your maven application using maven to compile and not eclipse, even though you are using eclipse as your IDE. Then by default maven will not copy resources from the source folder to the output folder... Because it is not the standard maven way of doing things. Thus the resource are missing from the classpath and you don't find them. Just change your maven configuration to also include resources from your source folder.
I think you have to add src/main/resources to the build path. This is done in Project Properties > Build Path > Source. Here is how the standard maven project looks:
In future when using Eclipse I suggest to use m2eclipse plugin and create project using it. This will automatically make sure that all these folders are in the build path.
Try this:
Run configurations... -> Classpath -> User Entries -> Advanced... -> Add Folders
Can you try loading the resources using below?
this.getClass().getClassLoader().getResourceAsStream(propertyFileName)
This might be useful information
Eclipse Maven plugin has its own Classpath Container that conflicts with generated class paths when enabled.
What I would suggest is stop using eclipse:eclipse (sorry - harsh I know). I used it for about 8 months, cant believe it took me that long, and used M2Eclipse. M2Eclipse is an eclipse plugin in which you do the following.
Enable Dependency Management.
Update Project Configuration
(In Eclipse) Project -> Build Project
(In Eclipse) Run Application
It may not seem it, but its a much easier and less frustrating way of doing it.
Before, with eclipse:eclipse. You would have to run it then hit refresh and hope that everything is configured - if you have a multi-module pom things can really go wrong.
For me the Files within the WEB-INF were not getting included. Hence I added them to Buildpath (Project -> Build Path -> Configure Build Path -> Add folder (project/src/main/webapp). This resolved the issue.

Categories

Resources