aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Eclipse: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Eclipse: "Java Project from Existing Ant Buildfile"" Watch "Eclipse: "Java Project from Existing Ant Buildfile"" New topic
Author

Eclipse: "Java Project from Existing Ant Buildfile"

Matt Hoover
Greenhorn

Joined: May 01, 2011
Posts: 21
I am working with swingx-ws for Java. The source code can be found here:

http://java.net/downloads/swingx-ws/releases/1.0/swingx-ws-1.0-src.zip

The project is unmaintained, and the package contains a few out of date dependencies. Following advice from HERE, I'd like to:

(1) open this source in Eclipse
(2) clean up the dependencies ("organize imports" per that post, which I'm hoping/assuming Eclipse can do automagically somehow)
(3) build a JAR file out of it all.

However, I cannot even seem to get past the first step (getting it open in Eclipse). I've tried "import existing projects into workspace" and "new Java project from existing Ant buildfile," but neither seem to work.

My first attempts at using the Ant Buildfile resulted in an error about a missing javac element in build.xml. So, I added the following line near the end of the <project> element:


However, now I get a new (and very vague) error, simply a pop-up stating java.lang.NullPointerException. No stack trace or anything, so I have no clue what that means in this context.

Thanks in advance for any help you can give!
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5837
    
    7

It usually helps us if you post the exact errors that you are seeing by using copy-and-paste to post the error messages here. I would like to see exactly what errors you are getting for 'new project form existing ant build'. And also post the full output that you are seeing when you run Ant.

As another tact, you could examine the Ant build script, dig through the source directories to understand how it is laid out, and then create a new project in Eclipse and copy the source files into that new project. The end result should be a buildable project. But it usually depends on how complex the original is.


JBoss In Action
Matt Hoover
Greenhorn

Joined: May 01, 2011
Posts: 21
Thanks for the reply, Peter.

Peter Johnson wrote:It usually helps us if you post the exact errors

I did post the exact error, and the full output, as far as I can tell. That's why I'm so lost. And that's why I linked to the source archive I'm using, so perhaps somebody familiar with Ant in Eclipse could take a look at it. To be even more explicit, here is what I do with that source archive:

1) Unpack this file to: C:\eclipse\swingx-ws-1.0-src\
2) Launch eclipse, choose File > New > Java Project from Existing Ant Buildfile
3) Select buildfile C:\eclipse\swingx-ws-1.0-src\build.xml
4) ERROR: Specified buildfile does not contain a javac task

So then I added the <javac> task as I specified in my OP. I'm not sure I've done that correctly though, hence my post here. But once I've done that, the above error goes away, I am able to select the new javac task and click "Finish," but I receive the new error. Again, I am pretty certain I posted it word for word in the OP, but to be more clear, here is a screenshot of the error.

Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5837
    
    7

Actually, you didn't post the full error text, you missed the most important part: "Error occurred, check log for details". So when you checked the log (it's at workspace/.log) what NPE stack trace did you see?

The "javac task found" message is simply informational - Eclipse is telling you that yes it found a statement in Ant that informed it where the source files are located and how to go about building them. This is usually not the important if the Ant build creates only a single JAR, but becomes more important if the Ant build creates several JARs, each of which uses different sets of source files.

Unfortunately, if Eclipse is having difficulties parsing the Ant build script (and running into an NPE will doing that), it might be very difficult to determine what construct in the build script that Eclipse is tripping over.
Matt Hoover
Greenhorn

Joined: May 01, 2011
Posts: 21
Sorry about that. Here is the log entry for the NPE:

!ENTRY org.eclipse.ant.ui 4 120 2012-12-08 18:14:06.973
!MESSAGE Error logged from Ant UI:
!STACK 0
java.lang.NullPointerException
at org.eclipse.ant.internal.ui.datatransfer.ProjectCreator.createSourceDirectories(ProjectCreator.java:86)
at org.eclipse.ant.internal.ui.datatransfer.ProjectCreator.createJavaProjectFromJavacNode(ProjectCreator.java:48)
at org.eclipse.ant.internal.ui.datatransfer.AntNewJavaProjectPage$4.execute(AntNewJavaProjectPage.java:397)
at org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(WorkspaceModifyOperation.java:106)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344)
at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:118)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)


I definitely do not know how to interpret that, I'm not familiar with any of those classes. Nor do I know if that <javac> line I added is correct at all. And most importantly, I'm not even sure I'm using "import from Ant file" as intended. I know that Ant specifies how to build Jar's from source. What I want to do though, is import those source folders into Eclipse as a project (which I will eventually build into a Jar at some point). If I manually drag the source folder into my workspace, there are all sorts of errors and missing dependencies, and Eclipse does not even know the directory layout of the insides of that source folder. Can that information be conveyed to Eclipse somehow, and if so is the Ant file even the right vehicle for that?

Thanks!
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5837
    
    7

The class where the NPE happened is processing the javac tag, perhaps there is some issue with the directories being used. I typical issue might be accessing a directory outside of the project's directory. (You could post the original <javac> tag from your build - looks like you posted your changes, all of which you should remove.)

You might have to create the project manually. If so, first, create a new project of the correct type in Eclipse.

Then drag the source files into the project. I usually do this from the file system (outside of Eclipse) and then in Eclipse I refresh the project (select the project, hit F5).

Then I dig through the Ant build script trying to figure out which JAR files are included in the build. I then add those to the project. (Well, actually, I always use Maven to do builds, so in reality I add the JARs as dependnecies in my POM and let the m2eclipse plugin update the Eclipse project with the JARs).

For simple builds this works great. For more complicated builds you might have to work at it. It helps if you understand what the Ant build does (usually running it is a first start, pay attention to the output and the order of the targets in the output).
Matt Hoover
Greenhorn

Joined: May 01, 2011
Posts: 21
Thanks for the continued responses, Peter.

Peter Johnson wrote:(You could post the original <javac> tag from your build - looks like you posted your changes, all of which you should remove.)


There actually was no original javac element, as I mentioned earlier this was the first error I encountered, which is why I tried to make a simple one myself (with admittedly no idea what I was doing).

I may not need this source code archive anymore, but if I do I will try to go about manually importing it as you suggested. Thanks again for your help.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5837
    
    7

There was no <javac> tag in the build.xml (or in any of the xml files included into build.xml)? Then I can see why Eclipse was confused - without a <javac> tag, Eclipse will not be able to figure out where you Java sources are. Sounds like you'll have to manually create a new project.
Matt Hoover
Greenhorn

Joined: May 01, 2011
Posts: 21
Peter Johnson wrote:There was no <javac> tag in the build.xml (or in any of the xml files included into build.xml)? Then I can see why Eclipse was confused - without a <javac> tag, Eclipse will not be able to figure out where you Java sources are. Sounds like you'll have to manually create a new project.

Well, the primary build.xml in the main directory does not contain a <javac> tag, but it does import two other xml files which seems geared toward the build and one of those does have a <javac> tag. However, trying to import from existing Ant Buildfile using this structure, I still get the error "Specified buildfile does not contain a javac task," which prevents me from clicking the next/finish button.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Eclipse: "Java Project from Existing Ant Buildfile"