2

I am a (very) amateur programmer. I am using Groovy to edit MP3 file tags. Previously (about two years ago), I added the JAudiotagger class library to my Java installation using the detailed instructions given in the JAudiotagger readme file, and then called the required classes from my Groovy script. However, there is no readme file (that I can find) in the latest version of JAudiotagger, and I have so far failed to work out what to do.

Please can someone give me simple instructions on how to add JAudiotagger to Java, e.g. what files do I need to download, from where and what do I do with them.

I am running Windows 7.

All help gratefully appreciated.

Opal
  • 81,889
  • 28
  • 189
  • 210
Jeremy Bartle
  • 87
  • 1
  • 8

2 Answers2

2

The easiest way is to simply download the jar of jAutioTagger and put it in your classpath, so when the program launch, the classes in the jar should be accessible: java classpath

Now if you want a more generic way of handling dependencies altogether, i suggest you start reading about maven (which a build tool with dependecny managment).

You can also use gradle which looks more for groovy but I do not know about it.

As for starting a new project with maven it requires some steps. Here is a lightweight tutorial:

  1. Create a maven project
  2. Add the desired dependencies in your pom.xml
  3. Build the project with libraries embedded
  4. Run the program

Create a maven project

Type in the following command in your command line:

mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=5-SNAPSHOT

It will ask you some questions like the group id and the artifact id as well as the project name.

Add the desired dependencies in your pom.xml

The pom.xml is where you configure your project, like build things and dependencies, to have audiotagger as a dependency add the following:

  <dependency>
      <groupId>org.jaudiotagger</groupId>
      <artifactId>jaudiotagger</artifactId>
      <version>2.0.1</version>
  </dependency>

This will add jaudiotagger to the dependencies of your project, you can add groovy as well. You'll also need dependencies too groovy and the groovy compiler.

Hint: I use sonatype to find dependencies

Build the project with libraries embedded

Now to build your project with maven. Just type the following command:

mvn clean install

but this will not add the dependencies to your jar, so you need to embedd them by adding a plugin to your pom.xml configuration:

   <artifactId>maven-assembly-plugin</artifactId>
   <configuration>
       <archive>
           <manifest>
               <mainClass>be.phury.audiotagger.Audiotagger</mainClass>
           </manifest>
       </archive>
       <descriptorRefs>
           <descriptorRef>jar-with-dependencies</descriptorRef>
       </descriptorRefs>
   </configuration>

You can now generate a jar with dependencies by typing in the command line:

mvn clean install assembly:single

Run the program

Just run the jar

Hope this helps

phury
  • 2,123
  • 2
  • 21
  • 33
  • Thank you so much! I've spent several days flailing around, downloading and umpacking jars, installing Maven and I don't know what else. It took me about one minute to follow your instructions and successfully access JAudiotagger from Groovy. I don't think I need Maven at the moment, and I don't really understand what it does, but I might explore the second part of your answer in the future. – Jeremy Bartle Oct 12 '12 at 11:11
1

If you do not want to go through Maven/Gradle, you could also use the @Grapes annotation:

@Grapes(
    @Grab(group='org.jaudiotagger', module='jaudiotagger', version='2.0.1')
)

in top of your Groovy script, that would download your dependencies whereever you start your script. I found the dependency http://mvnrepository.com/artifact/org.jaudiotagger/jaudiotagger/2.0.1 - they even make the full @Grapes notation for you.

sbglasius
  • 3,104
  • 20
  • 28