You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jclouds.apache.org by George Kousiouris <gk...@mail.ntua.gr> on 2014/10/05 18:54:24 UTC

Unable to export running jar with Jclouds code from eclipse

Hi all,

I have successfully run a project inside Eclipse, using a piece of code 
from Jclouds:
ComputeServiceContext context = 
ContextBuilder.newBuilder(provider)//"aws-ec2")
                 .credentials(user, apiKey)
                 //.modules(ImmutableSet.<Module> of(new 
Log4JLoggingModule(),
                   //                                new 
SshjSshClientModule()))
                 .buildView(ComputeServiceContext.class);

         ComputeService computeService = context.getComputeService();
         //System.out.println("After cs..");

         context.close();


The code is running fine within Eclipse, getting the server list and the 
metadata associated to them.   However, when i try to export a running 
jar file from Eclipse Juno, i get the following error from the command 
line execution:
java.util.NoSuchElementException: key [aws-ec2] not in the list of 
providers or
apis: {}
         at org.jclouds.ContextBuilder.newBuilder(ContextBuilder.java:174)

Seems to be a classpath issue? Any hints?

Thanks,
George







---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com


Re: Unable to export running jar with Jclouds code from eclipse

Posted by Yaron Rosenbaum <ya...@gmail.com>.
Hi

Your code depends on certain libraries both during compile time, but also during runtime (in this case it's the ec2 libraries).
When you run your code, make sure that you have all the required jars in your classpath.

If you use maven, you can do something similar to the config below. It will copy all your dependant jar files into /lib, and add them to your classpath in the jar manifest.


<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
				<executions>
					<execution>
						<id>copy-dependencies</id>
						<phase>prepare-package</phase>
						<goals>
							<goal>copy-dependencies</goal>
						</goals>
						<configuration>
							<outputDirectory>${project.build.directory}/lib</outputDirectory>
							<overWriteReleases>false</overWriteReleases>
							<overWriteSnapshots>false</overWriteSnapshots>
							<overWriteIfNewer>true</overWriteIfNewer>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<configuration>
					<archive>
						<manifest>
							<addClasspath>true</addClasspath>
							<classpathPrefix>lib/</classpathPrefix>
							<mainClass>---your-main-class------</mainClass>
						</manifest>
					</archive>
				</configuration>
			</plugin>
		</plugins>


(Y)

On Oct 5, 2014, at 7:54 PM, George Kousiouris <gk...@mail.ntua.gr> wrote:

> 
> Hi all,
> 
> I have successfully run a project inside Eclipse, using a piece of code from Jclouds:
> ComputeServiceContext context = ContextBuilder.newBuilder(provider)//"aws-ec2")
>                .credentials(user, apiKey)
>                //.modules(ImmutableSet.<Module> of(new Log4JLoggingModule(),
>                  //                                new SshjSshClientModule()))
>                .buildView(ComputeServiceContext.class);
> 
>        ComputeService computeService = context.getComputeService();
>        //System.out.println("After cs..");
> 
>        context.close();
> 
> 
> The code is running fine within Eclipse, getting the server list and the metadata associated to them.   However, when i try to export a running jar file from Eclipse Juno, i get the following error from the command line execution:
> java.util.NoSuchElementException: key [aws-ec2] not in the list of providers or
> apis: {}
>        at org.jclouds.ContextBuilder.newBuilder(ContextBuilder.java:174)
> 
> Seems to be a classpath issue? Any hints?
> 
> Thanks,
> George
> 
> 
> 
> 
> 
> 
> 
> ---
> This email is free from viruses and malware because avast! Antivirus protection is active.
> http://www.avast.com
> 


Re: Unable to export running jar with Jclouds code from eclipse

Posted by George Kousiouris <gk...@mail.ntua.gr>.
Hi all,

many thanks for your advice. At the moment as a bypass given that we 
needed a fast local solution, we have exported the dependent projects as 
a separate jar and added it directly in the build path of the project in 
question.

We will follow your instructions for the final implementation.

many thank,
George

On 10/6/2014 8:13 PM, Andrew Phillips wrote:
>> java.util.NoSuchElementException: key [aws-ec2] not in the list of
>> providers or
>> apis: {}
>>         at 
>> org.jclouds.ContextBuilder.newBuilder(ContextBuilder.java:174)
>>
>> Seems to be a classpath issue? Any hints?
>
> The problem here is most likely related to ServiceLoader: jclouds uses 
> a META-INF/... file to determine the implementations of API/provider 
> metadata classes that are available.
>
> If you create a "fat JAR", the default logic typically picks only 
> *one* of these files (or none of them), rather then merging them all, 
> which is what needs to be done. See [1] for some ways of achieving 
> this. If you're using Maven, there's also an example in 
> jclouds-examples [2].
>
> Hope this helps!
>
> ap
>
> [1] 
> http://blog.xebia.com/2011/07/20/jar-with-deps-dont-like-meta-infservices/
> [2] 
> https://github.com/jclouds/jclouds-examples/blob/master/compute-basics/src/main/assembly/jar-with-dependencies.xml
>
>


-- 
---------------------------

George Kousiouris, PhD
Electrical and Computer Engineer
Division of Communications,
Electronics and Information Engineering
School of Electrical and Computer Engineering
Tel: +30 210 772 2546
Mobile: +30 6939354121
Fax: +30 210 772 2569
Email: gkousiou@mail.ntua.gr
Site: http://users.ntua.gr/gkousiou/

National Technical University of Athens
9 Heroon Polytechniou str., 157 73 Zografou, Athens, Greece


---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com


Re: Unable to export running jar with Jclouds code from eclipse

Posted by Andrew Phillips <an...@apache.org>.
> java.util.NoSuchElementException: key [aws-ec2] not in the list of
> providers or
> apis: {}
>         at org.jclouds.ContextBuilder.newBuilder(ContextBuilder.java:174)
>
> Seems to be a classpath issue? Any hints?

The problem here is most likely related to ServiceLoader: jclouds uses  
a META-INF/... file to determine the implementations of API/provider  
metadata classes that are available.

If you create a "fat JAR", the default logic typically picks only  
*one* of these files (or none of them), rather then merging them all,  
which is what needs to be done. See [1] for some ways of achieving  
this. If you're using Maven, there's also an example in  
jclouds-examples [2].

Hope this helps!

ap

[1] http://blog.xebia.com/2011/07/20/jar-with-deps-dont-like-meta-infservices/
[2]  
https://github.com/jclouds/jclouds-examples/blob/master/compute-basics/src/main/assembly/jar-with-dependencies.xml