How to Read MP3 ID3 tags with Lucee

in my ACF site that i use to manage my radio station music library/SQL Database, I have been using this Java Library jid3lib-0.5.4.jar, following the instructions in Ray Camden’s splendid article from 2006 (That’s how old these pages are!!) Reading MP3 ID3 tags with ColdFusion

Now i’m in the new world of Lucee, I still need the same functionality. How would I read the contents of MP3 IE3 tags in Lucee? If i would use the same method Ray outlined for ColdFusion, where would I put the .jar file for the library? OR is there are better way to do it now?

Cheers
Mike Kear

To give additional information about what i’ve been doing (which clearly wont work now - but how to change it so it does work now is my problem.

javaobject = createObject(java, org.farng.mp3.MP3File);
mp3File = createObject(java, coldfusion.util.MP3File);

These two lines open the jar file, create the java object, and the second line creates a coldfusion object I can use to process the metadata.

How would I do this in Lucee?

It would work the same way in Lucee as far as your code. Regarding the jar, I highly recommend using this.javaSettings in your Application.cfc as it’s cross-engine compatible and works the same regardless of how CF is installed.

FWIW, a CommandBox-specific way would be to set app.libDirs in your server.json to point to the folder containing the jar to classload it.

Eitherway, once the jar is being loaded, the createObject() call will find it.

Thank you Brad. I have this all going except that Lucee isnt inding the java library If the libray is stored in the folder:

C:\Users\user.CommandBox\server\7496B9F85D8AC92F67A5164367FC8C7F-foggyhollow\lucee-5.3.9.133-SNAPSHOT\WEB-INF\lib

and the file is named :
jid3lib-0.5.4.jar

what do i put in this.javasettings? I’ve tried every syntax i can think of but i’m clearly not getting it right And i just KNOW that this is one of those situations where missing a period or a comma or a semicolon is enough to break it.

(I’m delighted to say the rest of my project to verify these sites all work fine in a Lucee environment with only a few tweaks is progressing super fast now. So thank you so much!!)

Cheers
Mike Kear

1 Like

Hi Mike

That’s the wrong lib folder. Put the jar in this one instead:

C:\Users\user.CommandBox\server\7496B9F85D8AC92F67A5164367FC8C7F-foggyhollow\lucee-5.3.9.133-SNAPSHOT\WEB-INF\lucee-web\lib

Then in CommandBox do restart foggyhollow and you should then be able to call the java library using

javaobject = CreateObject( "java", "org.farng.mp3.MP3File" );

Make sure you use quotes around "java" and the class name.

A downside of putting your jar file in the lib folder is that that location then becomes part of your code base. Should you make changes to the engine, those added jar files might get blown away and you’ll have to start again.

In Lucee there is a simple way of avoiding this, which doesn’t involve configuring javaSettings either.

  1. Stop your Lucee server
  2. Move your jar file out of the lib/ directory and put it in a folder within your app. e.g.
/myapp/
 index.cfm
 /jars/
   jid3lib-0.5.4.jar
  1. Start your server again
  2. Call the java library using a third argument to tell Lucee where it lives:
// index.cfm
jarPath = ExpandPath( "./jars/" );
javaobject = CreateObject( "java", "org.farng.mp3.MP3File", jarPath );
1 Like

I agree with Julian’s suggestions. Just be wary of anything that requires you to manually copy a jar around any time you start the server fresh. Here are some docs on this.javasettings

Search down the page for USING THIRD PARTY JAVA LIBRARIES (JAR FILES) IN CFML

component {
	this.name = "example";
	this.javaSettings = {
		loadPaths = ["/path/to/jarFile.jar"]
	};
}
1 Like

I have to testify that my site is running really fast!! I’m not sure whether it’s just because I’m expecting to or whether it’s really fast but it seems lightniing fast to me I’m delighted!!! If the production server runs at the same pace that will be fantastic. THank you all so much for your help getting me going on this migration!!!

Cheers
Mike Kear
Windsor, NSW, Australia

3 Likes