Java Code Examples for org.eclipse.jdt.core.IJavaProject#setOutputLocation()
The following examples show how to use
org.eclipse.jdt.core.IJavaProject#setOutputLocation() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BinFolderConfigurator.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException { IProject project = request.getProject(); if (compileToBin(project)) { IPath projectRoot = project.getFullPath(); IPath binPath = projectRoot.append("bin"); IPath binTestPath = projectRoot.append("bin-test"); IJavaProject javaProject = JavaCore.create(project); javaProject.setOutputLocation(binPath, monitor); IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); for(int i = 0; i < rawClasspath.length; i++) { IClasspathEntry entry = rawClasspath[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (isTest(entry)) { rawClasspath[i] = copyWithOutput(entry, binTestPath); } else { rawClasspath[i] = copyWithOutput(entry, binPath); } } } javaProject.setRawClasspath(rawClasspath, monitor); } }
Example 2
Source File: FixProjectsUtils.java From hybris-commerce-eclipse-plugin with Apache License 2.0 | 6 votes |
public static void setOutputDirectory(IProgressMonitor monitor, IProject project, IJavaProject javaProject) { IPath outputLocation = null, newOutputLocation = null; try { outputLocation = javaProject.getOutputLocation(); // Only change the output location if it is the eclipse default one "bin" if ("bin".equals(outputLocation.lastSegment())) { newOutputLocation = outputLocation.removeLastSegments(1).append("eclipsebin"); javaProject.setOutputLocation(newOutputLocation, monitor); } } catch (JavaModelException e) { System.err.println("project:" + project.getName()); System.err.println("outputLocation:" + outputLocation); System.err.println("newOutputLocation:" + newOutputLocation); Activator.logError("Could not set output directory", e); } }
Example 3
Source File: JavaUtils.java From developer-studio with Apache License 2.0 | 6 votes |
public static IJavaProject addJavaNature(IProject project, boolean rawClasspath) throws CoreException, JavaModelException { IProjectNature nature = project.getNature(ProjectConstants.JAVA_NATURE_ID); if(nature==null){ ProjectUtils.addNatureToProject(project, true, ProjectConstants.JAVA_NATURE_ID); } IJavaProject javaProject = JavaCore.create(project); IFolder targetFolder = project.getFolder("target"); targetFolder.create(false, true, null); javaProject.setOutputLocation(targetFolder.getFullPath(), null); Set<IClasspathEntry> entries = new HashSet<IClasspathEntry>(); if(rawClasspath){ entries.addAll(Arrays.asList(getClasspathEntries(javaProject))); } if(nature==null){ entries.add(JavaRuntime.getDefaultJREContainerEntry()); } javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null); return javaProject; }
Example 4
Source File: JavaProjectHelper.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
/** * Creates a IJavaProject. * * @param projectName * The name of the project * @param binFolderName * Name of the output folder * @return Returns the Java project handle * @throws CoreException * Project creation failed */ public static IJavaProject createJavaProject(String projectName, String binFolderName) throws CoreException { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject(projectName); if (!project.exists()) { project.create(null); } else { project.refreshLocal(IResource.DEPTH_INFINITE, null); } if (!project.isOpen()) { project.open(null); } IPath outputLocation; if (binFolderName != null && binFolderName.length() > 0) { IFolder binFolder = project.getFolder(binFolderName); if (!binFolder.exists()) { CoreUtility.createFolder(binFolder, false, true, null); } outputLocation = binFolder.getFullPath(); } else { outputLocation = project.getFullPath(); } if (!project.hasNature(JavaCore.NATURE_ID)) { addNatureToProject(project, JavaCore.NATURE_ID, null); } IJavaProject jproject = JavaCore.create(project); jproject.setOutputLocation(outputLocation, null); jproject.setRawClasspath(new IClasspathEntry[0], null); return jproject; }
Example 5
Source File: WebAppUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * Sets the project's default output directory to the WAR output directory's * WEB-INF/classes folder. If the WAR output directory does not have a WEB-INF * directory, this method returns without doing anything. * * @throws CoreException if there's a problem setting the output directory */ public static void setOutputLocationToWebInfClasses(IJavaProject javaProject, IProgressMonitor monitor) throws CoreException { IProject project = javaProject.getProject(); IFolder webInfOut = getWebInfOut(project); if (!webInfOut.exists()) { // If the project has no output <WAR>/WEB-INF directory, don't touch the // output location return; } IPath oldOutputPath = javaProject.getOutputLocation(); IPath outputPath = webInfOut.getFullPath().append("classes"); if (!outputPath.equals(oldOutputPath)) { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); // Remove old output location and contents IFolder oldOutputFolder = workspaceRoot.getFolder(oldOutputPath); if (oldOutputFolder.exists()) { try { removeOldClassfiles(oldOutputFolder); } catch (Exception e) { CorePluginLog.logError(e); } } // Create the new output location if necessary IFolder outputFolder = workspaceRoot.getFolder(outputPath); if (!outputFolder.exists()) { // TODO: Could move recreate this in a utilities class CoreUtility.createDerivedFolder(outputFolder, true, true, null); } javaProject.setOutputLocation(outputPath, monitor); } }
Example 6
Source File: ProjectCreator.java From txtUML with Eclipse Public License 1.0 | 5 votes |
public static void addProjectSettings(IProject project, ProjectSettings settings, boolean includeStdLib) throws JavaModelException { IJavaProject javaProject = JavaCore.create(project); List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); IExecutionEnvironmentsManager executionEnvironmentsManager = JavaRuntime.getExecutionEnvironmentsManager(); IExecutionEnvironment[] executionEnvironments = executionEnvironmentsManager.getExecutionEnvironments(); for (IExecutionEnvironment iExecutionEnvironment : executionEnvironments) { if (iExecutionEnvironment.getId().equals(settings.executionEnviromentID)) { entries.add(JavaCore.newContainerEntry(JavaRuntime.newJREContainerPath(iExecutionEnvironment))); break; } } IPackageFragmentRoot packageRoot = javaProject.getPackageFragmentRoot(settings.source); IPackageFragmentRoot packageRootSrcGen = javaProject.getPackageFragmentRoot(settings.sourcegen); entries.add(JavaCore.newContainerEntry(RuntimeLibraryContainerInitializer.LIBRARY_PATH)); if (includeStdLib) { entries.add(JavaCore.newSourceEntry(STDLIB_PATH)); } entries.add(JavaCore.newSourceEntry(packageRoot.getPath())); entries.add(JavaCore.newSourceEntry(packageRootSrcGen.getPath())); javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null); javaProject.setOutputLocation(settings.output.getFullPath(), null); }
Example 7
Source File: IDEOpenSampleReportAction.java From birt with Eclipse Public License 1.0 | 5 votes |
private void setClasspath( IProject project ) throws JavaModelException, CoreException { IJavaProject javaProject = JavaCore.create( project ); IPath path = project.getFullPath( ).append( "bin" ); //$NON-NLS-1$ javaProject.setOutputLocation( path, null ); IClasspathEntry[] entries = getClassPathEntries( project ); javaProject.setRawClasspath( entries, null ); }
Example 8
Source File: NewReportProjectWizard.java From birt with Eclipse Public License 1.0 | 5 votes |
private void setClasspath( IProject project ) throws JavaModelException, CoreException { IJavaProject javaProject = JavaCore.create( project ); if ( outputText.getText( ) != null && outputText.getText( ).trim( ).length( ) > 0 ) { IPath path = project.getFullPath( ).append( outputText.getText( ) ); javaProject.setOutputLocation( path, null ); } IClasspathEntry[] entries = getClassPathEntries( project ); javaProject.setRawClasspath( entries, null ); }
Example 9
Source File: TestUtils.java From CogniCrypt with Eclipse Public License 2.0 | 4 votes |
/** * This method creates a empty JavaProject in the current workspace * * @param projectName for the JavaProject * @return new created JavaProject * @throws CoreException */ public static IJavaProject createJavaProject(final String projectName) throws CoreException { final IWorkspaceRoot workSpaceRoot = ResourcesPlugin.getWorkspace().getRoot(); deleteProject(workSpaceRoot.getProject(projectName)); final IProject project = workSpaceRoot.getProject(projectName); project.create(null); project.open(null); final IProjectDescription description = project.getDescription(); description.setNatureIds(new String[] {JavaCore.NATURE_ID}); project.setDescription(description, null); final IJavaProject javaProject = JavaCore.create(project); final IFolder binFolder = project.getFolder("bin"); binFolder.create(false, true, null); javaProject.setOutputLocation(binFolder.getFullPath(), null); final List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); final IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall(); final LibraryLocation[] locations = JavaRuntime.getLibraryLocations(vmInstall); for (final LibraryLocation element : locations) { entries.add(JavaCore.newLibraryEntry(element.getSystemLibraryPath(), null, null)); } // add libs to project class path javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null); final IFolder sourceFolder = project.getFolder("src"); sourceFolder.create(false, true, null); final IPackageFragmentRoot packageRoot = javaProject.getPackageFragmentRoot(sourceFolder); final IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); final IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1]; System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length); newEntries[oldEntries.length] = JavaCore.newSourceEntry(packageRoot.getPath()); javaProject.setRawClasspath(newEntries, null); return javaProject; }
Example 10
Source File: MockJavaProjectProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
public static IJavaProject createJavaProject( final String projectName, String[] projectNatures) { IProject project = null; IJavaProject javaProject = null; try { project = IResourcesSetupUtil.root().getProject(projectName); deleteProject(project); javaProject = JavaCore.create(project); IProjectDescription projectDescription = ResourcesPlugin.getWorkspace().newProjectDescription( projectName); project.create(projectDescription, null); List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>(); projectDescription.setNatureIds(projectNatures); final ICommand java = projectDescription.newCommand(); java.setBuilderName(JavaCore.BUILDER_ID); final ICommand manifest = projectDescription.newCommand(); manifest.setBuilderName("org.eclipse.pde.ManifestBuilder"); final ICommand schema = projectDescription.newCommand(); schema.setBuilderName("org.eclipse.pde.SchemaBuilder"); projectDescription.setBuildSpec(new ICommand[] { java, manifest, schema }); project.open(null); project.setDescription(projectDescription, null); classpathEntries.add(JavaCore.newContainerEntry(new Path("org.eclipse.pde.core.requiredPlugins"))); javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]), null); JavaProjectSetupUtil.addJreClasspathEntry(javaProject); makeJava8Compliant(javaProject); javaProject.setOutputLocation(new Path("/" + projectName + "/bin"), null); createManifest(projectName, project); refreshExternalArchives(javaProject); refresh(javaProject); } catch (final Exception exception) { throw new RuntimeException(exception); } return javaProject ; }
Example 11
Source File: JavaProjectFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Override protected void enhanceProject(IProject project, SubMonitor monitor, Shell shell) throws CoreException { super.enhanceProject(project, monitor, shell); if (builderIds.contains(JavaCore.BUILDER_ID)) { SubMonitor subMonitor = SubMonitor.convert(monitor, 10); try { subMonitor.subTask(Messages.JavaProjectFactory_ConfigureJavaProject + projectName); IJavaProject javaProject = JavaCore.create(project); List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>(); for (final IProject referencedProject : project.getReferencedProjects()) { final IClasspathEntry referencedProjectClasspathEntry = JavaCore.newProjectEntry(referencedProject .getFullPath()); classpathEntries.add(referencedProjectClasspathEntry); } for (final String folderName : getFolders()) { final IFolder sourceFolder = project.getFolder(folderName); String outputFolderName = sourceFolderOutputs.get(folderName); final IClasspathEntry srcClasspathEntry = JavaCore.newSourceEntry(sourceFolder.getFullPath(), ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, outputFolderName == null ? null : project.getFolder(outputFolderName).getFullPath(), testSourceFolders.contains(folderName) ? new IClasspathAttribute[] { JavaCore.newClasspathAttribute("test", "true") } : new IClasspathAttribute[0]); classpathEntries.add(srcClasspathEntry); } classpathEntries.addAll(extraClasspathEntries); IClasspathEntry defaultJREContainerEntry = getJreContainerEntry(); classpathEntries.add(defaultJREContainerEntry); addMoreClasspathEntriesTo(classpathEntries); javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]), subMonitor.newChild(1)); javaProject.setOutputLocation(new Path("/" + project.getName() + "/" + defaultOutput), subMonitor.newChild(1)); String executionEnvironmentId = JavaRuntime.getExecutionEnvironmentId(defaultJREContainerEntry.getPath()); if (executionEnvironmentId != null) { BuildPathSupport.setEEComplianceOptions(javaProject, executionEnvironmentId, null); } } catch (JavaModelException e) { logger.error(e.getMessage(), e); } } }
Example 12
Source File: ProjectsManager.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
public static IProject createJavaProject(IProject project, IPath projectLocation, String src, String bin, IProgressMonitor monitor) throws CoreException, OperationCanceledException { if (project.exists()) { return project; } JavaLanguageServerPlugin.logInfo("Creating the Java project " + project.getName()); //Create project IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(project.getName()); if (projectLocation != null) { description.setLocation(projectLocation); } project.create(description, monitor); project.open(monitor); //Turn into Java project description = project.getDescription(); description.setNatureIds(new String[] { JavaCore.NATURE_ID }); project.setDescription(description, monitor); IJavaProject javaProject = JavaCore.create(project); configureJVMSettings(javaProject); //Add build output folder if (StringUtils.isNotBlank(bin)) { IFolder output = project.getFolder(bin); if (!output.exists()) { output.create(true, true, monitor); } javaProject.setOutputLocation(output.getFullPath(), monitor); } List<IClasspathEntry> classpaths = new ArrayList<>(); //Add source folder if (StringUtils.isNotBlank(src)) { IFolder source = project.getFolder(src); if (!source.exists()) { source.create(true, true, monitor); } IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(source); IClasspathEntry srcClasspath = JavaCore.newSourceEntry(root.getPath()); classpaths.add(srcClasspath); } //Find default JVM IClasspathEntry jre = JavaRuntime.getDefaultJREContainerEntry(); classpaths.add(jre); //Add JVM to project class path javaProject.setRawClasspath(classpaths.toArray(new IClasspathEntry[0]), monitor); JavaLanguageServerPlugin.logInfo("Finished creating the Java project " + project.getName()); return project; }
Example 13
Source File: PerformanceTestProjectSetup.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
public static IJavaProject createJavaProject( final String projectName, String[] projectNatures) { IProject project = null; IJavaProject javaProject = null; try { IWorkspace workspace = ResourcesPlugin.getWorkspace(); project = workspace.getRoot().getProject(projectName); deleteProject(project); javaProject = JavaCore.create(project); IProjectDescription projectDescription = ResourcesPlugin.getWorkspace().newProjectDescription( projectName); project.create(projectDescription, null); List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>(); projectDescription.setNatureIds(projectNatures); final ICommand java = projectDescription.newCommand(); java.setBuilderName(JavaCore.BUILDER_ID); final ICommand manifest = projectDescription.newCommand(); manifest.setBuilderName("org.eclipse.pde.ManifestBuilder"); final ICommand schema = projectDescription.newCommand(); schema.setBuilderName("org.eclipse.pde.SchemaBuilder"); projectDescription.setBuildSpec(new ICommand[] { java, manifest, schema }); project.open(null); project.setDescription(projectDescription, null); classpathEntries.add(JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"))); classpathEntries.add(JavaCore.newContainerEntry(new Path("org.eclipse.pde.core.requiredPlugins"))); javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]), null); makeJava8Compliant(javaProject); javaProject.setOutputLocation(new Path("/" + projectName + "/bin"), null); createManifest(projectName, project); // project.build(IncrementalProjectBuilder.FULL_BUILD, null); refreshExternalArchives(javaProject); refresh(javaProject); } catch (final Exception exception) { throw new RuntimeException(exception); } return javaProject ; }
Example 14
Source File: JReFrameworker.java From JReFrameworker with MIT License | 4 votes |
private static void configureProjectClasspath(IJavaProject jProject) throws CoreException, JavaModelException, IOException, URISyntaxException { // create bin folder try { IFolder binFolder = jProject.getProject().getFolder(BINARY_DIRECTORY); binFolder.create(false, true, null); jProject.setOutputLocation(binFolder.getFullPath(), null); } catch (Exception e){ Log.warning("Could not created bin folder.", e); } // create a set of classpath entries List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); // adds classpath entry of: <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> String path = org.eclipse.jdt.launching.JavaRuntime.JRE_CONTAINER + "/" + org.eclipse.jdt.internal.launching.StandardVMType.ID_STANDARD_VM_TYPE + "/" + "JavaSE-1.8"; entries.add(JavaCore.newContainerEntry(new Path(path))); // add the jreframeworker annotations jar addProjectAnnotationsLibrary(jProject); // have to create this manually instead of using JavaCore.newLibraryEntry because JavaCore insists the path be absolute IClasspathEntry relativeAnnotationsLibraryEntry = new ClasspathEntry(IPackageFragmentRoot.K_BINARY, IClasspathEntry.CPE_LIBRARY, new Path(JREF_PROJECT_RESOURCE_DIRECTORY + "/" + JRE_FRAMEWORKER_ANNOTATIONS_JAR), 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); entries.add(relativeAnnotationsLibraryEntry); // create source folder and add it to the classpath IFolder sourceFolder = jProject.getProject().getFolder(SOURCE_DIRECTORY); sourceFolder.create(false, true, null); IPackageFragmentRoot sourceFolderRoot = jProject.getPackageFragmentRoot(sourceFolder); entries.add(JavaCore.newSourceEntry(sourceFolderRoot.getPath())); // set the class path jProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null); if(JReFrameworkerPreferences.isVerboseLoggingEnabled()) Log.info("Successfully created JReFrameworker project: " + jProject.getProject().getName()); }