2

I am calling Processing functions from Java code.

This works fine for the standard Processing classes, but how to you import other Processing libraries; e.g. gicentre?

I've actually got it working by extracting the jar file from the processing library and then manually installing the artifact into the maven project.

Is there a proper way to do it?

PerceptualRobotics
  • 422
  • 1
  • 3
  • 18

2 Answers2

0

Add this dependancy in your maven pom.xml file.

<!-- mvnrepository.com/artifact/org.processing/core --> 
<dependency> 
   <groupId>org.processing</groupId> 
   <artifactId>core</artifactId> 
   <version>2.2.1</version> 
</dependency>
Sandip Solanki
  • 704
  • 1
  • 8
  • 15
  • this only imports the core library and not external libraries, such as gicentre. The maven dependency search for the external libraries does not return any results. – PerceptualRobotics Oct 25 '17 at 14:55
  • The latest version of Processing is 3.3.6. Version 2.2.1 should not be used anymore unless you have a specific reason to use an old version. – Kevin Workman Oct 25 '17 at 15:55
0

Sandip's answer will work for the core Processing library (with the caveat that you should use the latest version, not version 2.2.1), but like you've discovered, gicentre doesn't have a maven repository.

You can download the various gicentre libraries from this page. Each of those libraries comes as a .zip file that contains a .jar file.

Now that you have the .jar file, it's just a matter of adding that .jar to your classpath. How you do that depends on how you've set up your project. The simplest way to do it is to use the command line to compile your project, and then you'd use the -cp argument. You've said you're using Maven, so Googling "maven local jar" will lead to a ton of results, including this one: How to add local jar files to a Maven project?

But note that you don't have to use Maven. You could just set the classpath yourself, either via the command line or via your IDE settings. For simple projects, this can be a better option, especially if Maven is giving you trouble.

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107
  • I would recommend using Maven. The thing to do is to mvn install those JARs into your local .m2 repository. The benefits of Maven should not be discarded lightly. – duffymo Oct 25 '17 at 17:30
  • @duffymo Fair enough. But I would also say that the complexity of Maven should not be dismissed either. There are pros and cons that should be considered. Especially if OP is confused about how the classpath works in general, it could be a good idea to get some more practice under their belt before using Maven. – Kevin Workman Oct 25 '17 at 17:34
  • Fair enough. Your profile says you lurk in the processing tag and work at Google. This is a new library for me. What's the story? I've never heard of it until today. – duffymo Oct 25 '17 at 17:43
  • @duffymo Haha, my day job and my lurking in the Processing tag aren't related. Processing is a language/library that makes it easy to create visual, interactive programs without a ton of boilerplate code. Check it out: https://processing.org/ – Kevin Workman Oct 25 '17 at 17:47
  • As I said in my query I manually added the .jar extracted from the gicentre Processing library as a local jar using maven. Just thought there might be a more direct way of doing it. – PerceptualRobotics Oct 25 '17 at 19:03
  • @PerceptualRobotics The most direct way to do it is to set the classpath yourself. If you're using Maven, then there isn't a better way to do it. – Kevin Workman Oct 25 '17 at 19:10