15

Iam trying to implement JMS using eclipse.But when I tried to save the code, it showed that javax.jms.* cannot be resolved and there are no suggestions as well recommended by it.

How can I include it and use it? when I googled I found that javax.jms.* is not a part of java API,then how can I use it in eclipse and get my program run successfully?

I would like to implement JMS with the help of activemq,what all do I need to download and include in code?

Iam a newbie to this JMS, please suggest some references or sample code that can implement JMS using activemq.

Galaxin
  • 474
  • 2
  • 9
  • 21
  • 3
    You need to compile against either the JEE API, or an implementation. You'll need to run it with an implementation, like in an app container, with activemq, etc. – Dave Newton Mar 21 '12 at 17:37
  • Thanks but iam completely new to this JMS. can you please provide some references/tutorials on how JMS can be implemented using activemq? – Galaxin Mar 21 '12 at 17:52
  • Not any better than the ActiveMQ references/tutorials can. – Dave Newton Mar 21 '12 at 17:56
  • Thanks!! can u plz also guide me how to include the SDK that is downloaded (j2ee that has javax.jms.* included in it) in eclipse? Iam not sure how to remove that cannot be resolved error..:( – Galaxin Mar 21 '12 at 18:09
  • I updated the answer on how to do this. – Andreas Mar 21 '12 at 19:34

9 Answers9

28

When you download the activemq archive file from Internet. Extract this archive: /apache-activemq-x.x.x

cd into this apache... directory.

You will see activemq-all-x.x.x jar file.

Include this in your build path.

This should resolve your issue.

Vikram
  • 4,162
  • 8
  • 43
  • 65
5

If it is a maven project, add the following dependency to your pom.xml and it should start working as expected.

<dependency>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
<version>1.1</version>
</dependency>
mithun kanchi
  • 51
  • 1
  • 1
2

In addition to the answers already provided, if you are using Maven you can add the following dependency (available from Maven2 Central repo):

<dependency>
    <groupId>javax.jms</groupId>
    <artifactId>jms</artifactId>
</dependency>
2

When you have downloaded activemq zip file from http://activemq.apache.org then when you extract it, head on to .jar file of activemq(This jar file is required). Now from Eclipse do as follows:

  1. RightClick on Project and go to Properties
  2. Java Build Path tab
  3. Libraries tab
  4. Add External JARs...
  5. Get that .jar file from activemq folder
Pranav
  • 1,487
  • 2
  • 25
  • 53
2

There are actually many ways to fix this. As already stated in the comment you need the Java Enterprise Edition API. Java EE is an abstract specification so what you need is an implementation of the JMS API. Since JMS is part of the Java EE specification the easiest thing is to download a application server such as GlassFish (which is the reference implementation) or JBoss.

I assume you already got the Java compiler so you only need the SDK, not the JDK.

Java EE 6 SDK Update 4 A free integrated development kit used to build, test, and deploy Java EE 6 applications.

http://www.oracle.com/technetwork/java/javaee/downloads/index.html

Then after you have downloaded GlassFish you will end up with a lot of files that is an implementation of the different Java EE specification API's. You will probably want to download the plugin that I linked to beneath so that you can start, deploy and do many other administration task of your server from Eclipse. I do not use Eclipse so I don't remember if you want this version of Eclipse as well.

http://marketplace.eclipse.org/node/867

At last you want to add GlassFish to your buildpath.

I found this blog post (Scroll to "Create projects in Eclipse") if you are unsure what to add, but there are several blog posts on how to add GlassFish to the build path in Eclipse so I won't list them here.

http://www.webagesolutions.com/knowledgebase/javakb/jkb005/index.html

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Andreas
  • 2,450
  • 1
  • 18
  • 20
1

I fixed this problem by including the dependency of Activemq.

<dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-all</artifactId>
        <version>5.15.0</version>
</dependency>
0

It can be found in jboss-jms-api.jar

Will
  • 773
  • 1
  • 7
  • 24
0

If you are using/Testing ActiveMQ. Then configure your build path and add external jar activemq-all-.jar. (Path:In ) Clean and Build. This will helped me , will do same to you as well.

Danke,
Rahul.
rahulnikhare
  • 1,362
  • 1
  • 18
  • 25
0

If you want to resolve this issue using maven, then the correct maven dependency, available in maven repository, is the following:

    <dependency>
        <groupId>javax.jms</groupId>
        <artifactId>jms-api</artifactId>
        <version>1.1-rev-1</version>
    </dependency>

See post: The following artifacts could not be resolved: javax.jms:jms:jar:1.1

PrecisionLex
  • 801
  • 11
  • 26