Is there any open-source Java or JavaScript library available to parse .dwg files and get the objects from it.
I would like to extract data from a table of text for my project.
It seems that the AutoCAD developer community prefers .NET and C/C++ over JAVA.
The only free alternative I found is by converting .dwg to .dxf first and using the Kabeja lib to read from it.
Credits to all who have answered, I've tested all your proposition and here's what I've found , as of 2015:
There is currently no free AND reliable solution to read and manipulate .dwg and .dxf files. This applies especially to latest versions of AutoCAD, ex : Autocad 2010, Autocad 2013 etc, RF 2013, RF 2010.
Reliable (and expensive) solutions would be Teigha by ODA (2000$ a year) and RealDWG in C# by Autocad (5000$ a year)...
Cheaper alternatives are as such :
Open-source libraries such as Kabeja and YCad may be able to deal with older AutoCAD versions but do not expect much from them as these projects are inactive since a few years ago. It's worth to keep an eye out for Apache Tika though, since they started writing parsers for .dwg files but development has been slow.
On a personal note, I think that AutoDesk has a strong and selfish monopoly on the CAD market now and they are making it difficult for others to join in. The format's version of .dwg files changes so often and I guess open-source developers will have to give up at some point and use the official product instead.
Let's hope for more open-source solutions in the coming years
Autodesk developed AutoCAD mainly with a C++ and offers plug-in support for C++, .NET, JavaScript, VBA and LISP, that's why there is no native Java support. All of those will require AutoCAD installed on the machine.
Alternatively, you can use the AutoCAD I/O webservice, that is basically a running instance on the cloud, to run custom code and extract data or create new drawings. That will have support for all DWG features. Check http://developer.autodesk.com
As you pointed out, use DXF format instead, there is open source java library, YCAD also, that you can use and is very easy to use.
The Teigha library from opendesignaliance has C++, C#, and Java interface. Teigha is the alternative of RealDWG and it is widely used by many CAD software vendors. It is stable and has the power to read/edit/write dwgs without problem. We have more than 3 years of experience with it and I can say it is excellent and a lot cheaper. When we were at the point to choose between RealDWG and Teigha we chose Teigha and I am glad we did it.