Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » How to prepare correct JavaProject programatically
How to prepare correct JavaProject programatically [message #221233] Thu, 29 December 2005 10:05 Go to next message
Eclipse UserFriend
Originally posted by: wjancz.\/\/asko.pl (change \/\/ with w)

Hello,
I am trying to prepare JavaProject programatically, i am almost done, but
the problem is with creating specific folders.
First of - source folder - in Java Project labeled by yellow folder and
named "src",
Second - lib folder - in Java Project also labeled by yellow folder and
named "lib",

I attach little picture which shows what is my result,
there is snippet code which shows how i produced it:
Please read also comments - they would explain my "thoughts" :)

-- SNIPPET --


IJavaProject javaProject = javaProjectWizardPage.getNewJavaProject();


IFolder libFolder = javaProject.getProject().getFolder("lib");
try {
// creating lib folder...

libFolder.create(true, true, null);
Folder folder = null;

StringBuffer buffer = new StringBuffer();
InputStream inputStream = getFile("resources/binaryAction.template");
byte[] buf = new byte[1024];
int len = 0;
while ((len = inputStream.read(buf)) != -1){
buffer.append(new String(buf, 0, len));
}
inputStream.close();

// should create also src folder and fragmentRoot in this folder... but
don't know how ?????

IPackageFragmentRoot fragmentRoot =
javaProject.getPackageFragmentRoot(javaProject.getProject()) ;
IPackageFragment rootPackage =
fragmentRoot.createPackageFragment("pl.companyName.binaryActions ", true,
null);
rootPackage.createCompilationUnit("BinaryActionTemplate.java ",
buffer.toString(), true, null);

List classpath = new
ArrayList(Arrays.asList(javaProject.getRawClasspath()));
// adding lib binaryActions
IFile jarFile =
javaProject.getProject().getFile("lib/pl.wasko.binaryActions.jar ");
jarFile.create(getFile("resources/pl.wasko.binaryActions.jar "), true,
null);
IClasspathEntry classpathEntry =
JavaCore.newLibraryEntry(jarFile.getFullPath(), null, null);
classpath.add(classpathEntry);

// adding jdom lib
jarFile = javaProject.getProject().getFile("lib/jdom.jar");
jarFile.create(getFile("resources/jdom.jar"), true, null);
classpathEntry = JavaCore.newLibraryEntry(jarFile.getFullPath(), null,
null);
classpath.add(classpathEntry);
javaProject.setRawClasspath((IClasspathEntry[]) classpath.toArray(new
IClasspathEntry[classpath.size()]), null);

javaProject.save(null, true);
} catch (JavaModelException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

-- END SNIPPET --


the getFile(String fileName) method returns inputstream from which i can
read content of file stored in plugin folder...

What i am doing wrong ?
Maybe there are special methods which creates specific folders ? Or there is
a way to change nature of folder ???

Thank you for any help...

...::WojT::..


P.S. - Sorry for my english....


  • Attachment: navigator.JPG
    (Size: 16.64KB, Downloaded 140 times)
Re: How to prepare correct JavaProject programatically [message #221262 is a reply to message #221233] Thu, 29 December 2005 16:35 Go to previous message
Eclipse UserFriend
Hi,
It look like your project is root source folder.

Have a look here (page 13) for snippet:
http://eclipsecon.org/2005/presentations/EclipseCON2005_Tuto rial29.pdf

Hope it help
Mathias

Wojciech Jancz a écrit :
> Hello,
> I am trying to prepare JavaProject programatically, i am almost done, but
> the problem is with creating specific folders.
> First of - source folder - in Java Project labeled by yellow folder and
> named "src",
> Second - lib folder - in Java Project also labeled by yellow folder and
> named "lib",
>
> I attach little picture which shows what is my result,
> there is snippet code which shows how i produced it:
> Please read also comments - they would explain my "thoughts" :)
>
> -- SNIPPET --
>
>
> IJavaProject javaProject = javaProjectWizardPage.getNewJavaProject();
>
>
> IFolder libFolder = javaProject.getProject().getFolder("lib");
> try {
> // creating lib folder...
>
> libFolder.create(true, true, null);
> Folder folder = null;
>
> StringBuffer buffer = new StringBuffer();
> InputStream inputStream = getFile("resources/binaryAction.template");
> byte[] buf = new byte[1024];
> int len = 0;
> while ((len = inputStream.read(buf)) != -1){
> buffer.append(new String(buf, 0, len));
> }
> inputStream.close();
>
> // should create also src folder and fragmentRoot in this folder... but
> don't know how ?????
>
> IPackageFragmentRoot fragmentRoot =
> javaProject.getPackageFragmentRoot(javaProject.getProject()) ;
> IPackageFragment rootPackage =
> fragmentRoot.createPackageFragment("pl.companyName.binaryActions ", true,
> null);
> rootPackage.createCompilationUnit("BinaryActionTemplate.java ",
> buffer.toString(), true, null);
>
> List classpath = new
> ArrayList(Arrays.asList(javaProject.getRawClasspath()));
> // adding lib binaryActions
> IFile jarFile =
> javaProject.getProject().getFile("lib/pl.wasko.binaryActions.jar ");
> jarFile.create(getFile("resources/pl.wasko.binaryActions.jar "), true,
> null);
> IClasspathEntry classpathEntry =
> JavaCore.newLibraryEntry(jarFile.getFullPath(), null, null);
> classpath.add(classpathEntry);
>
> // adding jdom lib
> jarFile = javaProject.getProject().getFile("lib/jdom.jar");
> jarFile.create(getFile("resources/jdom.jar"), true, null);
> classpathEntry = JavaCore.newLibraryEntry(jarFile.getFullPath(), null,
> null);
> classpath.add(classpathEntry);
> javaProject.setRawClasspath((IClasspathEntry[]) classpath.toArray(new
> IClasspathEntry[classpath.size()]), null);
>
> javaProject.save(null, true);
> } catch (JavaModelException e1) {
> // TODO Auto-generated catch block
> e1.printStackTrace();
> } catch (FileNotFoundException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (CoreException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
> -- END SNIPPET --
>
>
> the getFile(String fileName) method returns inputstream from which i can
> read content of file stored in plugin folder...
>
> What i am doing wrong ?
> Maybe there are special methods which creates specific folders ? Or there is
> a way to change nature of folder ???
>
> Thank you for any help...
>
> ..::WojT::..
>
>
> P.S. - Sorry for my english....
>
>
>
Previous Topic:how to add rules for syntax highlighting
Next Topic:Custom SourceMapper
Goto Forum:
  


Current Time: Sat Jul 19 17:22:57 EDT 2025

Powered by FUDForum. Page generated in 0.03427 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top