12

In my Android app I use:

import javax.xml.bind.JAXBContext;

But I get:

The import javax.xml.bind cannot be resolved

I do have com.viewstreet.java.eclipse.jaxbplugin.JAXBPlugin in my plugins list.

BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96
MarcoS
  • 17,323
  • 24
  • 96
  • 174
  • Use simple XML instead. Jaxb requires libraries that android does nit include. So I wrote a blog post about simple in android to help with this common problem: http://massaioli.homelinux.com/wordpress/2011/04/21/simple-xml-in-android-1-5-and-up/ – Robert Massaioli May 01 '11 at 21:48
  • Please do not re-post; I've merged the 3 times you asked this... – Marc Gravell May 01 '11 at 22:43

6 Answers6

16

@commonsware is correct , just add respctive JAXB API jars in lib folder of your projet or in case of maven project add dependency in pom file

<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.1</version>
</dependency>

viz in my case on linux, solved the issue

shreeramaute
  • 362
  • 3
  • 14
6
  1. Go to https://javaee.github.io/jaxb-v2/ and download the standalone distribution (link at the very bottom of page).
  2. jaxb-ri-2.3.1.zip or whatever version is the latest shall be downloaded. Unzip it and copy the jaxb-ri\mod\jaxb-api.jar from the unzipped folder into the plugins folder of your eclipse installation directory.
  3. Go to eclipse, open your project, right click project name in Projects panel (left most) and choose Properties => Build Path
  4. Under Libraries tab, select Classpath and then click Add External JARs button. Browse and select the file you just copied to eclipse's plugins folder.
  5. Click Apply and Close

Just import your required javax.xml.bind classes and your project shall be built instantly.

Dia Sheikh
  • 190
  • 2
  • 16
5

Put the JAR in the project's libs/ directory, then add it to the build path via the Add JARs button. That's my standard recipe, and it seems to work, and it has the advantage of putting the JAR in the right spot for command-line builds as well.

At this point, though, I suspect that you will get a compile error. Generally, you cannot import classes in the java and javax packages into an Android project.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
4

Download jax-b.jar and add it as external jar in your project.

BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96
dipak
  • 41
  • 1
1

Any import cannot be resolved in Java means a class you referenced is not found anywhere on the classpath. You need the library you're trying to use added to your classpath. In Eclipse, that's in project properties in the Java Build Path => Libraries tab. If you don't have the jar file that contains the API you're trying to use, you probably need to get it from http://jaxb.java.net/.

Jonathon Faust
  • 12,396
  • 4
  • 50
  • 63
  • I did download JAXB2_20110412.jar and added it to my project's Java Build Path, but nothing changed... :-( – MarcoS May 01 '11 at 17:03
  • @Marcos, reading from the website it says you need to double click on the jar you downloaded. The REAL jars you need are inside the jar -- when you double click on it, you'll be asked to accept a license agreement. When you click accept, it will extract everything into a jaxb directory. Inside that, there's a lib directory with jaxb-api.jar which is probably the one you actually need in Eclipse. – Jonathon Faust May 01 '11 at 17:18
0

Adding a library/JAR to an Eclipse Android project

Community
  • 1
  • 1
Thane Anthem
  • 4,093
  • 4
  • 26
  • 24