How to define an external source folder in .pydevproject? - pydev

Are there any examples of how to add an external source directory to the pythonpath in the .pydevproject file? The pydev UI appears to require string substitution variables for this, which I have not been able to get working.
Thanks!
-Travis

You can add them as External Libs.
Project Properties > Pydev - PYTHONPATH > External Libraries > Add Source Folder

For completeness, here's the .pydevproject code that gets this working:
<pydev_pathproperty name="org.python.pydev.PROJECT_EXTERNAL_SOURCE_PATH">
<path>/home/travis/git/apollo/util/src/java</path>
...
</pydev_pathproperty>

Related

Eclipse Package Declaration Work Around?

The team in which I'm working doesn't use eclipse and wants the src folder to be setup a certain way. I, on the other hand, am using eclipse. They would like the src folder to have, for example, the following structure: src/main/java/com/* However, they would like package declarations to only have com.* in them. If I go to project->properties and in the source tab remove the src folder as a source folder and then _only add the com.* folder as part of the source_ it will show com.* as a package, but I still have to add the whole path from src down in the .java files. Here's an example of what I have to do in order for eclipse to recognize the packages:
package main.java.com.parser;
And what the team wants is to have main and java just be a folder so the package declaration would just be:
package com.parser;
So although the file structure would still be src/main/java/com/parser, the package name would be as stated in the later example.
Is there a way to do this in eclipse? I've seen some people asking similar questions on here, but they seem to have no concern that the whole path must be part of the package declaration.
I would much prefer not to do this this way, but no one else is using eclipse on this project.
Thanks for any help in advance.
In the Package Explorer, right click the src folder and select Build Path > Remove from Build Path
Then find the src/main/java folder, right click java and select Build Path > Use as Source Folder
Basically this tell eclipse that java is the folder which contains the packages and source files.
P.S. This is a very normal project setup for building with Maven. If you download the m2e (Maven to Eclipse) plugins and choose to create a Maven Project (or import from the pom.xml) then Eclipse will automatically know how to correctly locate the source folder.

Netbeans created JAR classpath

I have setup inside Netbeans to include a classpath pointing to a directory (properties) on my project folder as seen in the picture below. The folder contains the properties files that the project is using.
Now the problem is that when I use the Netbeans Clean and Build function, it generates the dist folder alright. No properties folder is created... I manually copy over the properties folder in the project folder to this dist folder.
However, the program is not able to detect the properties files. Anyone have any clue as to why it can work inside Netbeans (F6 function key) and not able to work when in command line.
(I simply typed at command line: java -jar MyApp.jar)
Thanks!
I solved it by using this method explained here: http://creechy.wordpress.com/2012/08/31/adding-custom-class-path-entries-to-a-netbeans-java-application-project/

Pydev: Go to arbitrary module source?

In Pydev, is there a convenient way to open arbitrary (external, globally installed) module? Say, I want to see the source of markdown.blockprocessors module. How can I do that without typing an import directive (import markdown.blockparser), using "Go To Definition" (F3) and removing the directive? It would be nice to see the hierarchy of the whole markdown package in the Package Explorer, but I don't know how.
There are 2 main ways of finding something without using F3:
Open Resource action (Ctrl+Shift+R): allows you to find any file in your workspace (so, it's useful not only for python modules, but any file, but those need to be in your workspace).
The PyDev tokens browser (Ctrl+Shift+T): allows you to find any token (class/method/attributes/globals -- but currently not module name) for modules in the PYTHONPATH (either source folder or external libraries under the project properties > pydev pythonpath). You can filter things as 'myproject.*something' (the dialog that opens provides instructions on how to filter tokens).
Add Markdown source code folder here::
Project properties -> PyDev PYTHONPATH -> Source folders.

Most efficient way of setting up a project Pydev PYTHONPATH in Eclipse (Helios)?

I want to add all folders in my Pydev project to PYTHONPATH so that I can reap the benefits of easily seeing unused imports etc. To do this I seemingly have to add all folders manually including the subfolders, one by one. Is there any way to add them all at once (recursively) or am I doing this completely wrong?
Now I right click the project in the Navigator and select Preferences. From there I go to Pydev-PYTHONPATH and finally I can add the folders.
Ok, just to give a proper answer, you should just add the folder(s) that you want to be in the PYTHONPATH as your source folder(s).
So, if you have a structure such as
/myproject
/myproject/src
/myproject/package
/myproject/package/__init__.py
/myproject/package2
/myproject/package2/__init__.py
You'd only want to add /myproject/src as your PYTHONPATH.
If you really had multiple folders to add there, you could edit the .pydevproject file (which is at the root of your project) and add multiple folders there at once (although as noted, you should only have few folders there, so, this is generally not needed -- although sometimes you may want that if you're adding multiple libraries to a folder or something alike).
The PyDev FAQ explains this properly on the items listed below:
How do I import existing projects/sources into PyDev?
How do I import existing projects/sources for a Django project into PyDev?
Check this out, this worked for me.
if you get an error “unresolved import: pydevd” try saving the file ‘manage.py’ first. the error should go away.
If the error persists: you need to make sure pydev is in your PYTHONPATH.
a) Go to Eclipse>Preferences>PyDev>Python Interpreter:
b) Click New Folder> (mac)”/Applications/Eclipse/plugins/org.python.pydev_x.x.x.x/pysrc”
c) Click “Apply” This adds the folder that contains pydevd.py to your PYTHONPATH. Eclipse automatically adds that to your project’s Python Library. This should resolve the problem and you can run it now.
https://djangounchain.files.wordpress.com/2012/12/screen-shot-2013-01-06-at-3-49-02-pm.png
(This should be a Comment to Fabio's answer, but insufficient rep)
(PyDev 2.7.1.2012100913)
Adding folders to the PythonPath does not work for EFS/Remote folders (rse://...)
When you click 'Apply' gives:
An internal error occurred during: "Python Nature: rebuilding modules".
java.lang.NullPointerException

Editor does not contain a main type

Just going through the sample Scala code on Scala website, but encountered an annoying error when trying to run it.
Here's the code: http://www.scala-lang.org/node/45. On running it on Eclipse, I got this message 'Editor does not contain a main type' that prevents it from running.
Is there anything I need to do...i.e break that file into multiple files, or what?
In Eclipse, make sure you add your source folder in the project properties -> java build path -> source. Otherwise, the main() function may not be included in your project.
I have this problem a lot with Eclipse and Scala. It helps if you clean your workspace and rebuild your Project.
Sometimes Eclipse doesn't recognize correctly which files it has to recompile :(
Edit:
The Code runs fine in Eclipse
A simpler way is to close the project and reopen it.
You have to make sure that your .java files are in the .src folder in eclipse. I had the same exact problem until I got it figured out.
Just make sure that the folder you work in is added to the built path:
right-click your folder --> build Path --> Use as source Folder
and it should now find main therein.
You can try to run the main function from the outline side bar of eclipse.
I had the same problem. I tried all sorts of things. And I came to know that
My .java files were not linked and
they were not placed in the 'src' folder.
Things I did:
Project properties >> Java Build Path >> Source
Deleted the original 'src' folder which was empty using 'Remove' option
Added the source that contained my source .java files using the 'Add Folder' option
This solved the error.
Just close and reopen your project in Eclipse. Sometime there are linkage problems. This solved my problem
A quick solution:
First, exclude the package:
Right click on the source package >> Build Path >> Exclude
Then include it back:
Right click on the source package >> Build Path >> Include
What you should do is, create a Java Project, but make sure you put this file in the package file of that project, otherwise you'll encounter same error.
That code is valid. Have you tried to compile it by hand using scalac? Also, have you called your file "addressbook", all lowercase, like the name of the object?
Also, I found that Eclipse, for some reason, set the main class to be ".addressbook" instead of "addressbook".
you should create your file by
selecting on right side you will find your file name,
under that will find src folder their you right click select -->class option
their your file should be created
Make sure that your .java file is present either in the str package, or in some other package. If the java file with the main function is outside all packages, this error is thrown.
Have faced the similar issue, resolved this by right clicking on the main method in the outline view and run as Java application.
I just had this problem too. The solution is to make sure eclipse created the project as Java project. Just create a new Java project and copy your class into the src folder (and import the eventual dependencies). This should fix the problem.
The correct answer is: the Scala library needs to before the JRE library in the buildpath.
Go to Java Buildpath > Order and Export and move Scala library to the top
I had this problem with a Java project that I imported from the file system (under Eclipse Helios). Here's a hint: the src code didn't seem to be compiled at all, as no "bin" directory showed up.
I had to create a Java project from scratch (using the wizard), then compare the .project files of the non-working and working projects.
The project giving "Editor does not contain a main type" had this as the "buildSpec" in the .project file:
<buildSpec>
</buildSpec>
But the working project had this as the "buildSpec":
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
I copied this in, and the imported project worked.
I know my answer is for Java, but the same might be the issue for your Scala project.
May be the file you have created is outside the src(source) folder. Trying to call the class object(from the file located in the src folder) from the .java file outside the source folder results in the same error. Copy .java file to the source folder, then build it. The error will be gone.
I had the same problem. I had the main class out of the src package, in other folder. I move it in and correct folder and solved
run "eclipse -clean -refresh" from command line. This fixed the issue for me when all other solutions failed.
This could be the issue with the Java Build path.
Try below steps :
Go to project properties
Go to java Build Path
Go to Source tab and add project's src folder
This should resolve the issue.
If it is maven project please check the java file is created under src/main/java
If you are not getting please change the JRE path and create the java files in above folder structure
For me, in Eclipse 3.6, this problem occurs when my main method is not public. I caused the problem by having a main method like this:
static void main(String[] args)
The dubugger was unable to detect this by itself. I am pretty suprised Eclipse overlooked this.
In the worst case - create the project once again with all the imports from the beginning. In my case none of the other options worked. This type of error hints that there is an error in the project settings. I once managed to solve it, but once further developments were done, the error came back. Recreating everything from the beginning helped me understand and optimize some links, and now I am confident it works correctly.
Follow the below steps:
Backup all your .java files to some other location
delete entire java project
Create new java project by right click on root & click new
restore all the files to new location !!
File >> Import >> Existing Projects into Workspace >> Select Archive Filed >> Browse and locate file >> Finish. If its already imported some other way delete it and try it that way. I was having the same problem until i tried that.
One more thing to check: make sure that your source file contains the correct package declaration corresponding to the subdirectory it's in. The error mentioned by the OP can be seen when trying to run a "main type" declared in a file in a subdirectory but missing the package statement.
I have this problem too after I changed the source folder. The solution that worked for is just editing the file and save it.
Try 'Update Project'. Once I did this, The Run as Java Application option appeared.
In my particular 'Hello World' case the cause for this problem was the fact, that my main() method was inside the Scala class.
I put the main() method under the Scala object and the error disappeared.
That is because Scala object in Java terms is the entity with only static members and methods inside.
That is why Java's public static void main() in Scala must be placed under object.
(Scala class may not contain static's inside)