A solution for classpath is read-only in eclipse - java

I am receiving an error when i am trying to set a project from my co-worker into my work space.
He has few jar pointing to his local, when i am trying to edit the build path it say .classpath is read-only.
Is there any solution to over come this?
Thanks,
Tom

Change to "Navigator" view. And under your project ,right-click on the classpath file and uncheck the "read-only" option.
BTW, you do know that you need ALL the Jars for your project to compile right?

I also have the same issue. In my case i did following:
1. open .classpath file and copy its all content.
2. Delete .classpath file.
3. copy .classpath file from any of your other project and paste in current project.
4. open .classpath file and paste the content you copied from previous file.
now you can do changes in build path without any error

Infact ,browse to the location where you have the project,change the permission from "read only" recursively to all the sub folders.This would ensure all the files have the write permission.

I was facing the same issue. This is what I have done since I am not able to find the .classpath file in the navigator.
Go to the navigation mode,
1.source --> Organize imports
That worked for me, not so sure if this is the correct approach.

Related

How can I commit only a single .java file to git from an eclipse project?

I want to commit only a .java file to an already existing repository. I am using github for a class, and we are each given access to a private repo containing project information. I am supposed to add only a .java file to this repo, but I can't figure out how to do this. I have come close: I committed only the .java file, but it is inside a directory with the same name as my eclipse project.
Is there a way to commit only the .java file, without any of the project information, while keeping the project usable?
Thanks.
edit:
My goal is to have \git\repoName\MyFileName.java
as well as keeping the files already in \repoName\ and keeping the MyFileName.java in a usable eclipse project.
Is there a way to commit only the .java file, without any of the project information, while keeping the project usable?
yes, you will need to create a .gitignore file, and put the rest of your project into the gitignore file, (and also gitignore itself), that way, the only files that are tracked by git are the .java files.
As for the files being inside the directory with the same name as your project, take a look at where you cloned the git repo to, and make sure it is on the same level as your project files.
Take a look at this documentation
http://git-scm.com/docs/gitignore
https://help.github.com/articles/ignoring-files/
I think its much simpler than what you are expecting :)
You can do, git add, docs:
git add yourFileName.java
Now you can commit the .java file
git commit -m "I am updating only .java"
You can either reset or let it be as it is!!
git reset
reset will not have any history. So, be careful if you want to reset. In this scenario I think you dont have to reset. See here for some help.
See my answer on how to push/pull changes from eclipse into github. Let me know for any help on how to interact with github on eclipse.
You want to remove a subtree and create a new repo?
This is definnitely possible but you have to be careful. Creating a subtree only for file like yourFileName.java surprizes me a bit, but why?
For whatever reasons, see this for an easy way, and the original post is this Detach (move) subdirectory into separate Git repository
This blog might also help you.
I figured it out!!
The key was to add a source. You can do it when you create a project, one of the options will say "Link Source" or something along those lines.
You can also do it after a project is created:
Right click the project in Project Explorer. Go to Properties -> Java Build Path (on the left) -> Source (the first tab) -> "Link Source..."(button on the right)
Then just browse for the git repo folder that you already have and you're good to go! Just create new class files within /repoName in Project Explorer.
If anyone needs clarification or anything, let me know.

cannot paste clipboard contents into selected elements Eclipse

I'm trying to create a simple login form using servlets connected to database. But I got this error:
No JDBC driver found
I had added mysql-connector as external JAR file. After searching for solution on stackoverlow, it was suggested instead of adding it as external JAR file, copy paste it into WEB-INF/LIB folder. But whenever I try that, it gives me error:
Cannot paste clipboard contents into selected elements
How can I resolve this?
EDIT 1: Eclipse not allowing me to drag-drop either
To fix it in that case, extract the file(s) from the archive first(.rar,.tar,.zip), then c-and-paste the file into Eclipse. Works for me under Package Explorer, too.
OR Go for
project->clean
just go through that
Eclipse & JAR Hell
May be that Help you out !!
Instead of copy paste try to drag file and place it in web-inf/lib folder
please Be sure that the file is not from a zip folder.
If it is from zip folder extract it , then copy paste the file.
download winrar-x64 /winrar-x32
install winrar
now unzip ur files
copy paste in eclipse
Best Solution:
Yes i try to start learning JDBC and had to face this issue.
I read the stackoverflow posts but nothing seems to be solving my issue.
Then i did one thing
1.Right click the project
2.Go to properties
3.java Build path
4.libraries
5.Add external Jars
6.Add the jar file
7.hit ok to save
8.Then copy and paste same jar file into the project that you have done before
9.Success!you won't see any error prompt
I am happy now and i hope that you too when you follow this procedure 😊

Eclipse Hell . . . Failed to read the project description file (.project)

I think Eclipse is trying to make me miserable. A couple of hours ago, my project was working and compiling well. Suddenly that all changed. Eclipse somehow wipes out all changes I have made to my files(activity, manifest etc.) I make sure to save often but when I go to run the project, I get the error that I have a build error. I checked and there was none, so I go to close Eclipse, so I can reopen and see if the errors will go away. Instead what happens is Eclipse wipes clean all my files and I end up with a project on disk with lots of blank code files. I try to run anyway, and I get the error message below.
Failed to read the project description file (.project) for 'com.example.android.nfc.simulator.FakeTagsActivity.FakeTagsActivity'. The file has been changed on disk, and it now contains invalid information. The project will not function properly until the description file is restored to a valid state.
Anyone have an idea what in the world this is about and how I can rectify this?
I would recommend to wipe out all the eclipse related configuration files(make sure you take the backup if you have manually made some changes in those) and import the project again, by following
File -> Import... -> Existing Project into Workspace
Make sure you take the backup of whole project before doing this.
When Eclipse gets stuck in some obscure status, I usually find useful to recreate the .metadata folder in workspace directory. It is a drastic solution, but it usually works for me. After that you can reimport all your projects.
This happened to me because I had a conflict in my .project file. I opened it up in a text editor and fixed the conflict (in my case, removed from ====... to >>>branch..., as well as <<<HEAD) and then I was able to open the project in eclipse.
I was just encountering this same issue (using Zend Studio 12, which is built on Eclipse). My problem was that I was creating a project from a Remote Server, and I was just downloading everything, which also included the .project file from the old project. It wasn't showing this error until I'd closed the program and tried to open it again (which usually wasn't until the next day).
I seem to have resolved it by making sure not to download the .project when initializing the project.
If the .project file is a text file, so if you have it in version control you might want to copy it over from there.
Before you trying the following make a backup of your current project state.
Assuming you don't have an old copy, you can open it in a text editor and try to see if there is something obvious wrong.
If this fails, copy the source files of your project to a fresh location (without the eclipse configuration files) and import it as a new project into eclipse.
if you still have all of your other source (.java files, AndroidManifest.xml, resources), you might be able to get your project back by simply going to the folder containing the project, removing the .project file that you say is now empty, and then using the new project wizard to recreate the project (and .project file) for you from your existing tree of source.
from the menus, select File -> New... -> Project , and then, in the first dialog, choose Android Project from Existing Code .
if you had done anything special to the .project (reliance on specific .jar files or changes to classpath), you may have to re-do these steps after you re-create your project; but at least it should pick up the code you already have.
If all the files are empty, and you have no working Backup, I can't help. I would recommend to use proper version control in the future.
Use git or mercurial, they have nice UI integrations (see tortoisegit/tortoisehg).
To decouple the build process and library management from eclipse, take a look at maven or gradle, this might help you in future projects.
If you use git, complete the merge e.g. del the head in your androidmanifest.
I also got the Same Issue in Eclipse but the real problem is i removed the actual Source project folder from source location (from which eclipse is trying to take the project) to some other place hence my eclipse is unable to get web.xml file since it is not available. Now i changed my source project folder location to the path where eclipse is trying to search for. Issue Resolved for me.
Just delete the 'servers' folder in your workspace and try again.

Add a properties file to IntelliJ's classpath

I'm running a simple Java program from the IntelliJ IDE using the Run->Run menu. It works fine. Now I want to add log4j logging.
I added a resources folder under my project root.
I added a log4j.properties file in that folder.
I changed the code to log something.
What is the right way to tell IntelliJ to include the resources folder in the classpath so the properties file is seen?
With IntelliJ 8 I could guess like a drunk monkey and eventually get it to work. I have 9 now and I am wholly unsuccessful. I've been trying for an hour. How about an "Add to classpath" option somewhere? /fume /vent /rant
Try this:
Go to Project Structure.
Select your module.
Find the folder in the tree on the right and select it.
Click the Sources button above that tree (with the blue folder) to make that folder a sources folder.
Actually, you have at least 2 ways to do it, the first way is described by ColinD, you just configure the "resources" folder as Sources folder in IDEA. If the Resource Patterns contains the extension of your resource, then it will be copied to the output directory when you Make the project and output directory is automatically a classpath of your application.
Another common way is to add the "resources" folder to the classpath directly. Go to Project Structure | Modules | Your Module | Dependencies, click Add, Single-Entry Module Library, specify the path to the "resources" folder.
Yet another solution would be to put the log4j.properties file directly under the Source root of your project (in the default package directory). It's the same as the first way except you don't need to add another Source root in the Module Paths settings, the file will be copied to the output directory on Make.
If you want to test with different log4j configurations, it may be easier to specify a custom configuration file directly in the Run/Debug configuration, VM parameters filed like:
-Dlog4j.configuration=file:/c:/log4j.properties.
I have the same problem and it annoys me tremendously!!
I have always thought I was surposed to do as answer 2. That used to work in Intellij 9 (now using 10).
However I figured out that by adding these line to my maven pom file helps:
<build>
...
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
...
</build>
I spent quite a lot of time figuring out how to do this in Intellij 13x. I apparently never added the properties files to the artifacts that required them, which is a separate step in Intellij. The setup below also works when you have a properties file that is shared by multiple modules.
Go to your project setup (CTRL + ALT + SHIFT + S)
In the list, select the module that you want to add one or more properties files to.
On the right, select the Dependencies tab.
Click the green plus and select "Jars or directories".
Now select the folder that contains the property file(s). (I haven't tried including an individual file)
Intellij will now ask you what the "category" of the selected file is. Choose "classes" (even though they are not).
Now you must add the properties files to the artifact. Intellij will give you the shortcut shown below. It will show errors in the red part at the bottom and a 'red lightbulb' that when clicked shows you an option to add the files to the artifact. You can also go to the 'artifacts' section and add the files to the artifacts manually.
Faced a similar challenge adding files with .ini extensions to the classpath. Found this answer, which is to add it to Preferences -> Compiler -> Resource Patterns -> [...] ;*.ini
If you ever end up with the same problem with Scala and SBT:
Go to Project Structure. The shortcut is (CTRL + ALT + SHIFT + S)
On the far left list, choose Project Settings > Modules
On the module list right of that, select the module of your project name (without the build) and choose the sources tab
In middle, expand the folder that the root of your project for me that's /home/<username>/IdeaProjects/<projectName>
Look at the Content Root section on the right side, the red paths are directories that you haven't made. You'll want to put the properties file in a Resources directory. So I created src/main/resources and put log4j.properties in it. I believe you can also modify the Content Root to put it wherever you want (I didn't do this).
I ran my code with a SBT configuration and it found my log4j.properties file.
For those of you who migrate from Eclipse to IntelliJ or the other way around here is a tip when working with property files or other resource files.
Its maddening (cost my a whole evening to find out) but both IDE's work quite different when it comes to looking for resource/propertty files when you want to run locally from your IDE or during debugging. (Packaging to a .jar is also quite different, but thats documented better.)
Suppose you have a relative path referral like this in your code:
new FileInputStream("xxxx.properties");
(which is convenient if you work with env specific .properties files which you don't want to package along with your JAR)
INTELLIJ
(I use 13.1 , but could be valid for more versions)
The file xxxx.properties needs to be at the PARENT dir of the project ROOT in order to be picked up at runtime like this in IntelliJ. (The project ROOT is where the /src folder resides in)
ECLIPSE
Eclipse is just happy when the xxxx.properties file is at the project ROOT itself.
So IntelliJ expects .properties file to be 1 level higher then Eclipse when it is referenced like this !!
This also affects the way you have to execute your code when you have this same line of code ( new FileInputStream("xxxx.properties"); ) in your exported .jar.
When you want to be agile and don't want to package the .properties file with your jar you'll have to execute the jar like below in order to reference the .properties file correctly from the command line:
INTELLIJ EXPORTED JAR
java -cp "/path/to_properties_file/:/path/to_jar/some.jar" com.bla.blabla.ClassContainingMainMethod
ECLIPSE EXPORTED JAR
java -jar some.jar
where the Eclipse exported executable jar will just expect the referenced .properties file to be on the same location as where the .jar file is
Right-click on your directory and from Mark directory as select Resources root as below:
Perhaps this is a bit off-topic, seeing as the question has already been answered, but I have experienced a similar problem. In my case only some of the unit test resources were copied to the output folder upon compilation. My persistence.xml in the META-INF folder got copied but nothing else.
In the end I "solved" the problem by renaming the problematic files, rebuiling the project and then changing the file names back to the original ones. Do not ask me why this worked but it did. My best guess is that, somehow, my IntelliJ project had gotten a bit out of sync with the file system and the renaming operation triggered some kind of internal "resource rescan".
This is one of the dumb mistakes I've done. I spent a lot of time trying to debug this problem and tried all the responses posted above, but in the end, it was one of my many dumb mistakes.
I was using org.apache.logging.log4j.Logger (:fml:) whereas I should have used org.apache.log4j.Logger. Using this correct logger saved my evening.
I had a similar problem with a log4j.xml file for a unit test, did all of the above. But figured out it was because I was only re-running a failed test....if I re-run the entire test class the correct file is picked up. This is under Intelli-j 9.0.4

In Eclipse, how can I exclude some files (maybe based on the .svn extension or filename) from being copied to the output folder?

I'm developing a Java application using Eclipse. My project has two source directories that are both built and then some files are copied into the output folder. From the output directory I then run my application and all works well.
However, I keep having these warnings:
Snapshot from Problems tab in Eclipse http://www.freeimagehosting.net/uploads/128c1af93f.png
Anyone know how to get rid of these warnings? Maybe by excluding some files, maybe based on the .svn extension or filename, from the build process? If so, how would I go about excluding those?
Have you tried to add
**/.svn/
to the Exclusion patterns at the Source preferences of the project's build path settings?
You could also try installing the Subversion plugin (Subclipse) for Eclipse.
Sure, that easy:
at Project Properties -- Java Build Path you can add exclusion filters on every source folder.
There, you can add an exclusion pattern as *.svn
That sounds like your building process is using versionned directory within your subversion workspace.
Should you not have your 'output' folder and/or your 'tst' folder be made 'private' ? (that is without any .svn, and ignored by subversion)
Right click on the source file > Build Path > Exclude.

Categories

Resources