Im using play 2.0 and trying to modularize the project into a subproject.
In $project_home, created folder structure ${project_home}/data/app/models/MyModel.java
The Build.scala looks
val dataDependencies = Seq(
)
val dataProject = PlayProject(appName + "-data", appVersion, dataDependencies, path = file("data"), mainLang = JAVA)
val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(
// Add your own project settings here
).dependsOn(dataProject).aggregate(dataProject)
I run a play eclpsify command.
In eclipse, I've imported two projects, the main project and the data project.
The data project shows the following error
Project '-data' is missing required library: '/path/to/myprojects/data/target/scala-2.9.1/classes_managed'
What am I doing wrong here? Any help would be appreciated
This is what worked for me (on Windows).
Edit .classpath, there should be an entry similar to this:
<classpathentry path="D:\your_play_project_folder\target\scala-2.10\classes_managed" kind="lib"></classpathentry>
Remove the path portion before "target" to get this:
<classpathentry path="target\scala-2.10\classes_managed" kind="lib"></classpathentry>
Refresh Eclipse.
I encountered the similar problem when building a project with play 2.0.2
I created manually the target/scala-2.9.1/classes_managed folder and I run clean all projects in eclipse
I hope it helps
I think you have 3 possibilities:
create data/target/scala-2.9.1/classes_managed manually.
Remove the path from class-path (if not necessary)
Switch to 2.1-snapshot
For me helped:
manually removed target/scala-2.9.1/classes_managed from the .classpath file
added target/scala-2.9.1/classes_managed via eclipse: project/properties/Java Build Path --> tab Libraries --> Add Class Folder...
Try "play clean" and then "play eclipse", to re-generate the eclipse project files from a command prompt in the project's base folder.
try this:
1) sbt> clean/compile in parent, followed by child project
2) add target/src-managed/main as source folder in eclipse, both projects
3) in child
java build path > projects > (add parent)
project references > (add parent)
What does dataProject do, btw? My base project provides a DAO layer and other nuts & bolts that have nothing to do with Play; therefore, I just define it as a root sbt project, and pull it in to child project via dependsOn(root)
Anyway, hope this gets the issue sorted...
Related
today I have a special problem which already took me a while at the debugger.
I have two projects Project A and Project B.
Project A has multiple src-directories.
src
├───main
│ └───java
└───generated
└───java
both are recognized by eclipse as actual src directories. Both will be compiled to bin which looks like this:
bin
├───main
└───generated
Project B has a Project-dependencie on Project A.
And now comes the strange part: When I look for a class from Project A/src/main/java via Class.forName() inside Project B it will be found. When i look for a class from Project A/src/generated/java I get a ClassNotFound exception.
I would be very glad if you could point out a way to tell eclipse to create a dependencie on both src-directories.
btw, just in case it is important: I am using java 9.
and here is an excerpt of .classpath from Project B
<classpathentry kind="src" path="/Project A"/>
Thanks for your help.
This looks like a bug of Eclipse, Gradle or a combination of both. Try to delete the run configuration and restart the application. Make also sure the gradle.build file is in sync with the Eclipse project. If all this doesn't help, you can use a single output folder as workaround:
Manually in Project > Properties: Java Build Path, in the tab Source:
Uncheck the checkbox Allow output folders for source folders
In the field Default output folder enter bin/main
or via following gradle.build snippet:
apply plugin: 'eclipse'
eclipse.classpath.file.whenMerged {
entries.find { it.path == 'src/main/java' }.output = 'bin/main'
entries.find { it.path == 'src/generated/java' }.output = 'bin/main'
}
I have some ast parser code in eclipse but I am unable to import the
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTParser;
packages.
could some body tell me which jar file to download and where to add same that jar file in eclipse folder.
You probably have those files downloaded already in eclipse\plugins folder i.e. in windows C:\Program Files\eclipse\plugins\org.eclipse.jdt.core_3.9.1.v20130905-0837.jar
Of course you can download from internet as well
http://central.maven.org/maven2/org/eclipse/tycho/org.eclipse.jdt.core/
Note that in order to run it as a stand alone application you will have to import such librariers (where xx stands for version and again they can be found in eclipse\plugins folder):
org.eclipse.core.contenttype_xx.jar
org.eclipse.core.jobs_xx.jar
org.eclipse.core.resources_xx.jar
org.eclipse.core.runtime_xx.jar
org.eclipse.equinox.common_xx.jar
org.eclipse.equinox.preferences_xx.jar
org.eclipse.jdt.core_xx.jar
org.eclipse.osgi_xx.jar
Usually people add other libraries in folder called lib but still you will have to set it in eclipse. In order to do that right click on your project then build path -> configure build path -> libraries and select add JAR.
I was wondering if there is a difference in SBT between a project's name and id.
I noticed example build.sbt files with the following key:
name := "My Project"
And I noticed Build.scala files with:
Project(id = "My Project", base = file("."))
Is there a difference? Should the two be the same or is it irrelevant? What are they used for?
Thanks!
Project name should be used for the name of your project, the visible title for any documentation.
Id is used to refer to the project to modify settings or in terms of dependancy management, i.e to connect a subproject to a root project you can say subproject.dependsOn(rootProjectId)
In your build.sbt file you have a single project definition. You can also pass a name attribute to the settings of a Project in your build.scala. As you can have several sub projects in a build file, you have to provide an id for each of them, while the project name remains the same.
I'm sure this is simple, but I haven't figured it out yet...
I've installed sbt-launch.jar and a shell script to execute it (named sbt).
How do I put multiple projects in the same directory?
When I run sbt the directories project and target get created and populated, and the current project is default-XXXXX. The compile command picks up source files in the top-level directory and jar files in the top-level 'lib' directory.
How do I add another project under the same directory? Every time I run sbt in an empty directory it creates a 20+ MB project directory.
Note 1: when I run sbt I an not getting asked "Create new project?" or any other questions.
Note 2: I am using sbt-launch.jar from this url: http://typesafe.artifactoryonline.com/typesafe/ivy-releases/org.scala-tools.sbt/sbt-launch/0.10.1/sbt-launch.jar
and I'm following the instructions at: http://code.google.com/p/simple-build-tool/wiki/Setup
Found the answer (for sbt 0.10.1):
Create the file project/Build.scala that looks like this:
import sbt._
object MyBuild extends Build
{
lazy val root = Project("root", file("."))
lazy val sub1: Project = Project("proj1", file("dir1"));
lazy val sub2 = Project("proj2", file("dir2"))
}
This creates three projects 'root' (in the top-level directory), 'proj1' (in the sub-directory 'dir1') and 'proj2' (in the sub-directory 'dir2')
For more info, see https://github.com/harrah/xsbt/wiki/Full-Configuration
How can I create a new build path entry for any *.jar file and add this classpath entry to the build path of an Eclipse project.
I have a plugin that should automatically setup my target project. So this project needs to have some library imports and I want to add this imports automatically using a wizard. The user just selects the location of a certain SDK and then some libraries have to be linked with the target project.
However, I found some references:
Importing libraries in Eclipse programmatically
How to add a folder to java build path as library, having multiple jars or entries in it?
Unfortunately, I failed to implement the second solution as I cannot find the classes IClasspathContainer, JavaCore and IJavaProject.
I'm using Eclipse Helios and JDK. Do I need any additional libraries to make changes to the build path or is there a simpler solution to import a jar library programmatically?
Regards,
Florian
I'm assuming that you are creating a plugin and need your plugin to manage the extra jars added to the classpath.
As you mention, you need to create a custom classpath container. First, create the classpath container extension by exending this extension point:
org.eclipse.jdt.core.classpathContainerInitializer
Then, you create a class that implements org.eclipse.jdt.core.IClasspathContainer and associate it with the extension point you just created.
You mention that you cannot find the org.eclipse.jdt.core.IClasspathContainer interface. You need to make sure that your plugin references the org.eclipse.jdt.core plugin in its MANIFEST.MF.
Here you can find some examples, how to define new classpath entries and classpath containers to java projects. I think it would handy for someone reading this question.
In order to get access to IJavaProject etc, goto your plugin.xml and add org.eclipse.jdt.core to the classpath. Thereafter you can import those packages into your project.
String projectName = "MyProject"; // project to add a library to
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
IJavaProject jProject = JavaCore.create(project);
for(File file : new File("path-to-some-directory-of-libraries-to-add").listFiles()){
if(file.isFile() && file.getName().endsWith(".jar")){
addProjectLibrary(jProject, file);
}
}
private static void addProjectLibrary(IJavaProject jProject, File jarLibrary) throws IOException, URISyntaxException, MalformedURLException, CoreException {
// copy the jar file into the project
InputStream jarLibraryInputStream = new BufferedInputStream(new FileInputStream(jarLibrary));
IFile libFile = jProject.getProject().getFile(jarLibrary.getName());
libFile.create(jarLibraryInputStream, false, null);
// create a classpath entry for the library
IClasspathEntry relativeLibraryEntry = new org.eclipse.jdt.internal.core.ClasspathEntry(
IPackageFragmentRoot.K_BINARY,
IClasspathEntry.CPE_LIBRARY, libFile.getLocation(),
ClasspathEntry.INCLUDE_ALL, // inclusion patterns
ClasspathEntry.EXCLUDE_NONE, // exclusion patterns
null, null, null, // specific output folder
false, // exported
ClasspathEntry.NO_ACCESS_RULES, false, // no access rules to combine
ClasspathEntry.NO_EXTRA_ATTRIBUTES);
// add the new classpath entry to the project's existing entries
IClasspathEntry[] oldEntries = jProject.getRawClasspath();
IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1];
System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length);
newEntries[oldEntries.length] = relativeLibraryEntry;
jProject.setRawClasspath(newEntries, null);
}
Note that as Andrew Eisenberg mentioned, you need to include the org.eclipse.jdt.core plugin dependency in your plugin's MANIFEST.MF.
Note that you may also need to programmatically refresh the project too.