i'am using the Player class from javazoom (javazoom.jl.player.Player) to play mp3 files. From within my Netbeans IDE (version 7.4), sounds are played successfully. But as soon i start my program from outside the IDE, sounds are not played anymore!
Does anyone know what the reason could be?
PS: Both, Netbeans IDE and Java environment outside in windows uses the same java framework: Java 1.7.0_40
Thank you
i guess i have solved it now with two steps:
1.) I used the MP3 SPI from http://www.javazoom.net/mp3spi/sources.html to play sounds
2.) I have a Netbeans maven project and i use filtering in case of resources, so i have to exclude the folder where sounds are saved, otherwise the sound files become corrupted when Netbeans is copying files to target folder and are not recognized as mp3 files anymore:
<resources>
<resource>
<directory>resources</directory>
<targetPath>../resources</targetPath>
<filtering>true</filtering>
<excludes>
<exclude>data/sounds/**</exclude>
</excludes>
</resource>
<resource>
<directory>resources</directory>
<targetPath>../resources</targetPath>
<filtering>false</filtering>
<includes>
<include>data/sounds/**</include>
</includes>
</resource>
</resources>
Now, even short mp3 files works as expected!
Related
I have developed a project with swing, maven with some native libraries. Now i have an issue with calling SO from java after generating jar from maven package. I included so in POM.xml. And it included that file inside jar.But it wont link both.
I had an error while executing jar like
" Exception in thread "main" java.lang.UnsatisfiedLinkError: no projectso in java.library.path"
<resources>
<resource>
<filtering>false</filtering>
<directory>${project.basedir}/lib</directory>
<includes>
<include>my.so</include>
<include>cv2.so</include>
</includes>
</resource>
</resources>
And also want to add library folder and export it into jar.Is there any way to do it?
Your native library path is not correct for your program to run. see Call c function from Java
use -Djava.library.path=/path/to/libs to set the path before executing the program.
use System.loadLibrary("HelloWorld") to set the path in runtime
please take look at the link I post again.
I feel like I'm going round in circles with this, so hopefully its something relatively easy to solve.
For the application I'm developing I want to have a set of XML files which contain configuration information. And I would like these to be editable without having to re-compile the jar file. So what I would like is to have them in a folder called resources in the same folder as the jar file.
So my intended structure is something like
root
|
- app.jar
|
- resources
|
- config
|
- config1.xml
- config2.xml
I have managed to adjust my pom.xml so that it will copy the resources into my target folder using copy-resources within the maven-resource-plugin.
I've also added my resources directory as a resource (so that it works within eclipse) using
<resources>
<resource>
<directory>resources</directory>
</resource>
</resources>
so that I can access them using
getClass().getResource("/config/xml/config1.xml");
And included my resources directory on the classpath of the manifest of the jar (I think) using manifestEntries in the maven-jar-plugin.
<manifestEntries>
<Class-Path>. resources</Class-Path&>
</manifestEntries>
And attempted to exclude my resource from being compiled into the jar file using
<configuration>
<exclude>resources/**/*.xml</exclude>
</configuration>
they are still getting compiled into the jar file. And if I remove them from the jar file manually then I get a null pointer exception when attempting to access the resource.
So what I'm trying to achieve, and need help figuring out is
a way to obtain the structure I've roughly outlined above for external resources which are not compiled into the jar file but which are are accessible (via the classpath) by code within a jar in the same root directory and which still functions in eclipse.
Any help or guidance would be appreciated.
You have missed tag excludes
<configuration>
<excludes>
<exclude>resources/**/*.xml</exclude>
</excludes>
</configuration>
You can complicatedly exclude all folder like this :
<excludes>
<exclude>config/</exclude>
</excludes>
or just all xml files from config
<excludes>
<exclude>**/config/*.xml</exclude>
</excludes>
I have used this how2 to add the Version number to our produkt: http://www.christophkiehl.com/easy-way-to-display-your-apps-version-using-maven-and-manifest
when i now build a jar with mvn assembly:single i see the correct version.
But when i just run everything with mvn exec:java i get null...
what do i have to do that App.class.getPackage().getImplementationVersion() does not return null when i just start the programm from the non-jar?
The technique that you have used to add version number works only when built as a jar.
A different way to achieve the same would be to have a properties file which gets updated with the project version during build, which in turn is read by your java code.
Say, you have a file version.properties in src/main/resources, which has an entry
product.version=${project.version}
In the place you call App.class.getPackage().getImplementationVersion(), you read this property and display the contents.
This will work in both jar and non-jar case.
Update: You would need to update the pom to enable filtering for resources - essentially add a snippet like the below (refer this for details).
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
I'm using NewRelic for monitoring. I want Maven to package both newrelic.jar and newrelic.yaml files into my WEB-INF/lib inside the war file. With the newrelic.jar there is no problem since it's a simple dependency, but newrelic.yaml is a resource file. It resides in resources directory. I want Maven (war plugin) to copy it to WEB-INF/lib when packaging the war.
Thanks.
Alex
While I agree with #matt b that this is odd, here's what you can do:
Try changing the configuration of the maven war plugin to include a webResource:
<configuration>
<webResources>
<resource>
<directory>pathtoyaml</directory>
<includes>
<include>**/*.yaml</include>
</includes>
<targetPath>WEB-INF/lib</targetPath>
</resource>
</webResources>
</configuration>
The directory is relative to the pom.xml. See the plugin's documentation for more info.
You can also specify most configuration for the New Relic agent including the location of the config file via flags passed to the java command. In this case, it's something like:
-Dnewrelic.config.file=/etc/newrelic.yml
(ok, it's exactly like that, but you need to specify whatever path you need if it's not that.)
You should try adding .yaml file to newrelic.jar's resources, later
you can access it via classpath.
Or try changing/overriding build.xml build target by adding something like < copy file=".yaml"
todir="WEB-INF/lib" />
Try googling for more info on changing build.xml.
I am trying to create a maven build for one of our legacy projects. Since one of the requirements is to be still compatible with the legacy ant build script I can't change the project directory structure.
The problem is the current directory structure which is as follows:
+ src
+ java
+ com
+ whatever
+ whatever2
+ resources (!)
My goal is to have source directory src/java and resource directory src/java/com/whatever/whatever2/resources.
Obviously I need to set <sourceDirectory>src/java</sourceDirectory>. This is fine.
But I would also need to make the resources maven resource directory. Trying the following:
<resources>
<resource>
<directory>src/java/com/whatever/whatever2/resources</directory>
</resource>
</resources>
But once I do this and run mvn clean package it gives me:
[INFO] No sources to compile
Once I remove the <resources> section the module is compiled just fine and have all the classes inside. Any tips on how to solve this? Thanks
We have a similar setup (XMBean descriptors next to the MBean implementations using them), but exclude java files from the resources:
<resource>
<directory>src/main/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>