What, in Eclipse, modifies a project's .classpath to add the attribute exported="true" to classpathentry? - adt

Looking at a .classpath file of a project that I inherited, I found the following difference between the committed file (to Git) and the working directory:
- <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
If I am to revert that via the Eclipse GUI, what in the project's properties do I need to change?

Found it!
The exported="true" or exported="false" in the .classpath file is determined by checking/unchecking the checkboxes that are accessible by Right-click project > Build Path > Configure Build Path... > Order and Export [tab]

Related

.java is not on the classpath of project, only syntax errors are reported

I could not find a proper answer to this error in other posts.
I am using Maven for building my project in VS Code and whenever I create a class this error appears.
Do I need to do anything with .classpath file?
Correct me if I am mistaken, this error is pointing out that the class is not recognized by the .classpath file in which it belongs to, so I have to address it in that file.
Tnx
It seems like no one else knew it!
The problem was regarding "folder convention" and "maven-dependency-plugin".
As I created my Maven project with the line below via windows command line, maven did not install dependency-plugin and that created the first problem.
Second, what I meant by "folder convention" was, deleting "java" folder which is created by executing bellow Maven command line, caused me a problem since Maven compiler does not find any Java project to go to and execute codes. Deleting Java folder will also lead to the error above because no Java file is recognized, so no java files will be added to .classpath folder respectively.
mvn archetype:generate -DgroupId=name -DartifactId=name -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
I had the same problem.
From Welcome screen, go to Student-->Getting Started-->FAQ-->Find the "Why do I see tons of problems and red squiggles?" portion and click " Clean Workspace". That fixed my problem.
I have the same problem.
Just close the vscode and open it again.
Hope it works
Since i was using a different structure from what the maven project expected i had to manually change the .classpath file from pointing to the wrong folder. Only after this that my imports started to be correctly resolved.
Original:
<classpath>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
...
Modified path attribute:
<classpath>
<classpathentry kind="src" output="target/test-classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
...
I had the same problem and it was just about folder structure of vscode. when you created java file, it would have created a .java file (and maybe a .class file). Just simply move the .java file into src folder and .class file into bin folder and the problem is solved.
link of screenshot if you need
i have noticed when i open multiple cmd to type "code . " this error occurs
try to close all CMD's and reopen project i think it will go away
Simply create your files inside the src folder your problem will be solved.
" If you already created them outside the src folder move them into src folder"

IntelliJ: Invalid .iml location and content when I choose "create new project" over "open existing project"

I have several question about how the project structure is created and stored. Here is the context: I have a git repository containing some groovy files which I use for a Jenkins library. So what is interesting us here is the "src" folder, which contains groovy classes, and the "vars" folder, which contains groovy scripts (DSL).
There's no existing IntelliJ project, no .idea folder, no .iml, no pom.xml ...
Let's say that the repository is located under:
C:\Toto\JenkinsLibrary
- .git
- src
- vars
My objective is to create a Maven project from scratch.
First Method:
Initially, I open IntelliJ and choose "Create new project". Select "Maven", no archetype, then I enter the following information:
Project name: I leave the project corresponding to the artifactID: JenkinsBuildLibrary
Project location: C:\Toto\JenkinsLibrary
More settings: Module name = JenkinsLibrary, Content root = Module file location = C:\Toto\JenkinsLibrary, Project format = .idea
Then click finish
Here, the .iml file is generated OUTSIDE the .idea folder, looking like this:
C:\Toto\JenkinsLibrary
- .git
- .idea
- src
- vars
- JenkinsLibrary.iml
- pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Then soon after the content of the iml goes to:
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />
Also, I have been trying to reproduce this several times and it is extremely complex to get a consistent behavior, sometimes I have the iml file with no generated pom, sometimes I have the pom with no iml .... so I guess there's a huge bug here.
Finally, if I change the project structure by adding other sources folder or other modules, nothing changes in my .iml file. Then I can close IntelliJ, remove ALL .idea, .iml and pom.xml files ... to get everything back once I reopen IntelliJ, leaving me to wonder: where is that configuration actually stored ?!
Second method:
This time, I choose "Open existing project". I select the folder: C:\Toto\JenkinsLibrary
There's no existing project but it still works and create a new project.
The .iml file is now under the .idea project !!
C:\Toto\JenkinsLibrary
- .git
- .idea
- JenkinsLibrary.iml
- src
- vars
- pom.xml
Right click the module, select "Add Framework Support", Maven, and I get a pom file.
When I change the project structure, the .iml is correctly updated. Exemple:
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<content url="file://$MODULE_DIR$/../../tools/ToolJenkins/src">
<sourceFolder url="file://$MODULE_DIR$/../../tools/ToolJenkins/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Now If I close IntelliJ, remove ALL .idea, .iml and pom.xml files ... I don't get anything back once I reopen the project (only the files and folder located under the module), which seems a far better behavior !
SHORT SUMMARY:
When creating a new Maven project, the .iml is located at the root of the project instead of under the .idea folder and is invalid. The project structure seems to be stored elsewhere. I have no way to ship a valid project to my teammates.
When opening a new project, the .iml is located under the .idea folder and is valid. The project structure is stored under it (with warnings that project are defined by a pom file and changes performed under the Project structure menu could be wiped). I can ship a valid project to my teammates.
I need to understand those differences and how IntelliJ works. I hope for a quick answer since this is not the first time we struggle with project structures and may well move back to another, more stable IDE is necessary.
Thanks !
IntelliJ IDEA stores generated project files externally for Maven or Gradle based projects. You should never edit them manually or adjust any content roots and source roots via the interface as they are managed by the build system configuration (pom.xml) in your case.
To change or add additional source roots you need to modify pom.xml directly.
It looks like your directory layout doesn't follow the standard Maven convention. You may need to override it or add additional directories.

Where are Visual Studios Debugging settings saved?

When I change the Debugging settings in the Project Properties (in my case especially the Environment value) it is not saved to the project or solution file.
Where is it saved?
Thanks to the Stack Overflow question Should I add the Visual Studio .suo and .user files to source control I was able to solve the question with Chris Nielsens answer which I quote here:
You can open both the .user and the .csproj files in any text editor. I just tested copy-pasting the relevant debug settings from the .user into the .csproj, then deleting the .user file. Debugging continued to work, happily reading the correct settings from their new location in the .csproj file. This should provide a way to commit debug settings without committing the .user file. Be sure you put them in the right configuration (debug, release, etc.). Works on my machine! =)
I just copied:
<LocalDebuggerEnvironment>PATH=$(CxPathd);%PATH%</LocalDebuggerEnvironment>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
from the .user file to the .vcxproj file to the same section of the document:
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
In my case these where the only entries in the .user file so it would be okay in my case to check them into the SCM but it maybe cleaner to copy it to the .vcxproj file.
Those settings are saved in the projectname.vcxproj.user file, located in the same directory as the project file. It looks like this for example:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ShowAllFiles>true</ShowAllFiles>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommandArguments>
</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerEnvironment>PATH=$(CxPathd);%PATH%</LocalDebuggerEnvironment>
</PropertyGroup>
</Project>
If you are using the new SDK-style projects, debug settings are now stored in ./Properties/LaunchSettings.json. They are shared between all projects in the same folder.

Is there a way to add source files to visual studio project from command-line?

I want to use sublime to edit a visual studio project.
I have a custom build:
{
"cmd": ["c:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\MSBuild.exe"],
"working_dir": "${project_path:${folder:${file_path}}}/../Project"
}
But if I add new files I also need to include them in the project.
Is there a way to do this from the command line, maybe at compile-time?
I am working with opengl using c++;
I basically set up a project using one of the examples provided on the opengl website.
Then I opened the project folder in sublime text and successfully compiled it using the custom build system.
However, when I add NEW source files to the project (*.h and *.cpp) I get a linking error.
I get the same error when I build in visual studio.
The error disappeared after I had included the files by manually browsing and adding them to the project.
What I wanted was a way to automatically add all the source files in a folder to the project(via command line, or wildcard or smth else).
This way I can easily work on a vs2010 project in sublime, add new source files and build the project.
Or maybe there already is a better workflow for this?
You could try to modify your .vcxproj file to include any .h and .cpp file in your project folder or folders below.
In case of a c++ VS project you can try to alter your .vcxproj file like this:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- rest of project file untouched -->
<!-- start of modified part -->
<ItemGroup>
<ClInclude Include="**\*.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="**\*.cpp" />
</ItemGroup>
<!-- end of modified part -->
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
Be aware that adding files to your project from inside VS at later point will replace the modification described above!
As an alternative you could also create an external project file holding the same <ItemGroup /> elements described above and include this project file into your .vcxproj.
I'll add an example of this alternative if you're interested.

run the spring project from command line

I have created one spring project in STS (spring source tool) which works (compile and execution) fine in STS, but when I am run the class file from terminal I am getting an error like this:
Exception in thread "main" java.lang.NoClassDefFoundError: com/XXXX/XXXX/Operations
Caused by: java.lang.ClassNotFoundException: com.XXXX.XXXX.Operations
For reference below is my .classpath file:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java" />
<classpathentry kind="src" output="target/test-classes"path="src/test/java" />
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/
org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5" />
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER" />
<classpathentry kind="output" path="target/classes" />
<classpathentry exported="true" kind="var" path="M2_REPO" />
</classpath>
Your error suggests that the "Operations.class" file is not in the target/classes folder (or you have a typo in your package name).
First ensure your class is where you expect it:
cd [project root]/target/classes
ls com/XXXX/XXXX/Operations.class
If this proves the file is present, you should be able to use the java command you mentioned:
java com.XXXX.XXXX.Operations
Make sure you do not add ".class" at the end, as Java will assume you are trying to load a file called "class" in the "Operations" package.
If the file is missing (I expect it will be), you will need to execute a build in STS (Project -> Build Project) to create it.
Update
You mention in the comments that you are getting the error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
This is a very different problem, it means you have not referenced the Spring libraries in your java command, so Java doesn't know where to find them.
I recommend you package the program with STS before attempting to run it. This is the typical way Java developers build and deploy applications. This article provides a simple tutorial on how to do this (STS is a variant of Eclipse).
Addition - your updated question suggests you are also using Maven in this application, in which case you can use "mvn package" to build the project instead of Eclipse. Read this tutorial to get started on using Maven: http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
If you REALLY want to run the program without packaging it; you will need to reference ALL the Jar files you are using in the command (this is only an example, replace "spring.jar" with the correct Jar files you are using):
java -classpath .;../../lib/spring.jar com.XXXX.XXXX.Operations
Usually, people creates jar-file, which contains all classes and resources need to start the application. After that, its easy to start the app:
java -cp youapp-full.jar com.XXXX.XXXX.Operations
And Operations class must have main method ofcourse

Resources