I've spent the entirety of yesterday and the start of today trying to find out why Codenvy is using Java 8, but cannot find the JavaFX library that is included with it. I've looked through the files of the machine and cannot find it anywhere. I've also attempted to add it natively as a Source jar, but Codenvy seems to have removed support for this. On top of this, their tutorial page for adding source jars has been replaced with how to set up Che. I just use the Codenvy website and keep everything on the cloud.
So my problem is that I cannot get sound (MP3) to play. I tried the project on a workspace I set up in Codenvy previously, and it worked without an issue... yet a workspace made post Codenvy Beta release doesn't work, the JavaFX library just isn't there. The workspace from the older Codenvy doesn't have a stack (see below). Where as the newer projects do. I've tried workspaces with all the stacks that include Java, and still nothing. I did put the project into the old workspace and it worked flawlessly, but the old workspace doesn't have all the features of the newer ones, like ctrl+space for auto-complete, ect. I may aswell be using Notepad.
Is anyone else experiencing this, and is there a way to fix it?
Below is also my pom.xml so you can see the configuration.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>TMMOJ</groupId>
<artifactId>TMMOJ</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<argLine>-Xmx1024m</argLine>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<compilerVersion>1.5</compilerVersion>
</configuration>
</plugin>
</plugins>
Managed to get this working by adding the jfxrt.jar from the JDK .tar.gz from the official java website to a lib folder, and adding it as a dependency (as described in one of the answers to this question JavaFX 2 as a Maven dependency). This solved the problem.
Related
I am developping in java for five years and I am also using Maven for almost five years.
I am currently working on a proximity chat project in order to get some knowledge about multi-threading, network, SourceDataline and TargetDataline. For bandpass optimization I need to find a way to encode the bytes array that represents a samples coming from the microphone.
I know that Mumble already propose this technology but I want to do it by myself even if it will not be as efficient. In the wiki it is written that the software is based on Audio codec which is written in C.
So that is the first time for me to use native code and therefore that is the first time I have to work with JNA.
THE PROBLEM: I am not able to load the library.
For flexibility, the all project is divided into several sub project listed here from the lowest layer to the higher:
communication: send/receive asynchronously byte from the network.
messenger: structure a message to send to the remote.
mumble-common: Gather the request a client can send to the remote or the server can send to each client. It depends on the projects communication and messenger.
sound: Simplify access to the microphone and speakers. It is this project that will integrate the dll in order to optimize the bandpass.
mumble-client: Package to send data to the server without knowing the message structure. It depends on the projects mumble-common and sound.
mumble-client-gui: It is the jar the final user use. It depends on the project mumble-client.
To work with audio codec in java, I found this project which is a java wrapper for the native dll. I added this project as dependency for my sound project (Adding the repositories and dependency maven tag in the pom). However when I try to run the mumble-client-gui from the IDE, I got this error :
java.lang.UnsatisfiedLinkError: Unable to load library 'opus': Native library (win32-x86-64/opus.dll) not found in resource path [resource path list]
Until now, this is what I tried :
Update the class path of sound from Eclipse but first I got the same error and second I had to furnish a absolute path which is not what I want to do because the project will be deployed on several machines.
Use maven-nativedependencies-plugin but I did not get a big changes.
Integrate the dll directly in my sound project using JNA but it throws an exception because the dll is not registered in the class path.
Copy/past the dll into a known Directory and load it using :
System.load("absolute/path/to/library")
but I got another exception : The dll is in 32 bit whereas the JVM is in 64 bit but the dll is really in 64 bit. For me that is a secondary issue if I can load and use the dll directly with JNA (using the already implemented java wrapper or using directly JNA and the dll manually).
So right now I have absolutely no idea of what I am missing..
The solution I am looking for should respects the following criteria:
It should works if mumble-client-gui is running from the IDE or from the jar and if I have to modify the resource path, I'd rather to precise a relative path.
Feel free to ask for more details and for source code ! :)
Here is the pom.xml of the sound project :
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.pederobien</groupId>
<artifactId>sound</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>sound</name>
<url>http://maven.apache.org</url>
<properties>
<author>Pierre-Emmanuel41</author>
<project.build.sourceEncoding>Cp1252</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<repositories>
<repository>
<id>tomp2p.net</id>
<url>http://tomp2p.net/dev/mvn/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>fr.pederobien</groupId>
<artifactId>utils</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>net.tomp2p</groupId>
<artifactId>opus-wrapper</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
<build>
<finalName>sound</finalName>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<targetPath>./src/main/resources/natives</targetPath>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources/natives</directory>
<includes>
<include>libopus.dll</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>src</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
You don't need any maven configuration as that's mostly for the JVM itself and won't impact JNA's library loading. You can configure the JNA search paths from Java, though, at your program start-up.
From the JNA javadocs, you can set jna.library.path to the directory you want to search for all DLLs. This will be searched in addition to platform-specific search locations for system DLLs.
System.setProperty("jna.library.path", "your/path/here");
Alternately you could set a search for a specific library with addSearchPath()
NativeLibrary.addSearchPath("opus", "your/path/here");
Okay based on the solution proposed by Daniel Widdis,
I put this code :
NativeLibrary.addSearchPath("opus", "src/main/resources/win32-x86-64/opus.dll");
into a static block of the ExternalEncoder, the class that will use directly the java wrapper. In that case the library is loaded only once.
It seems working because I don't get any error by now. But I found something strange that maybe you can explain to me :
I am using eclipse and when I save the ExternalEncoder, then in my folder "\target\classes" it creates the directory win32-64-x86 with the dll inside. When I delete it, remodify ExternalEncoder and save it, then the directory is recreated.
Where it comes from ? From Eclipse ? From Maven ? The win32-64-x86 directory name ?
I know that there's a lot of question related to this issue but none made sense for me. I built a Java Desktop application that adds products for sale by communicating with an API. I am using okhttp 3.9.0 to accomplish this task. The problem is that my app works just fine when I execute the Netbeans' "run project" command but when I use the "java -jar file.jar" command to run the app I get exceptions stating that okhttp3 classes weren't found. That's the first time I try to run a Java application outside of an IDE so I kind of lost.
I am running my app from:
C:\Users\Diego Alves\.m2\repository\com\mycompany\loja\1.0-SNAPSHOT
Also, something that bugs me is that when searching for okhttp3 I generally end up on an Android-related page. Isn't okhttp3 used for desktop apps?
You need to add dependencies to your jar(okhttp is one of them) so that the JVM can find them in your classpath. To do that, in pom.xml add the following plugin:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>your.package.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
Also make sure you have set <packaging>jar</packaging>
Then run the build (mvn clean install), it will generate a jar that can be executed successfully.
java -jar target/your_jar_name.jar
For OkHTTP there is no link with android, you can use it in any Java Application.
After some hours of trying I give up. After converting my java project to maven in Eclipse, I can't seem to run the application via the main class.
Have changed source folder to src/main/java and added some changes to my pom file, but still dosen't work. What am I forgetting?
I'm totally new to Maven, but have read alot stack posts, but none seem to solve the issue.
pom file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.NorthQStandAloneJava</groupId>
<artifactId>NorthQStandAloneJava</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<description>
Simple UI based program that can switch on a Qplug from NorthQ
</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.Controller.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
Have already done the following:
1 - Run install maven
2 - Run as java application and pointing to the main class in the Controller folder
Hope someone can tell me what I'm doing wrong.
You must change:
<packaging>pom</packaging> to <packaging>jar</packaging>
and
<mainClass>com.Controller.Main</mainClass> to <mainClass>Controller.Main</mainClass>
Plus: remember java code conventions (packages must be lowercase)
Until now i made runnable jars with Ant and there were no problems with it.
However i now try to mavenize my project and i realy can't figured out how to do runable jar with this tool.
I've read tons of tutorials (also here, on Stackoverflow), helps, advices and... nothing. In my case all of them don't work which probably means i don't understand some basics.
I have such simple project:
This is app, witch use mysql-connector-java-5.1.24-bin.jar (placed in 'lib' dir) to connect to MySQL database.
I want to include this jar into final jar (DBPreformatter.jar).
I used assembly and shaded plugins in many configurations, but they NEVER added this jar into DBPreformatter.jar.
This is my pom.xml:
<modelVersion>4.0.0</modelVersion>
<groupId>com.icd4you</groupId>
<artifactId>DBPreformatter</artifactId>
<version>1.0.0</version>
<name>DBPreformatter</name>
<description>DB processing and cleaning tool</description>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>mysql-connector-java-5.1.24-bin</groupId>
<artifactId>mysql-connector-java-5.1.24-bin</artifactId>
<version>5.1.24</version>
<scope>system</scope>
<systemPath>${basedir}/lib/mysql-connector-java-5.1.24-bin.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<!-- WHAT SHOULD I USE HERE? -->
</plugins>
</build>
How to solve this problem?
There is a maven plugin Apache Maven Shade Plugin that will build an uber jar for you
Add the Maven Assembly plugin with the descriptor jar-with-dependencies:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.pany.your.MainClass</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
Note that this doesn't add the JAR; instead it unpacks all JARs which are listed as dependencies and adds their content to the resulting JAR (so you'll see all the class files from the MySQL JAR in the result instead of the MySQL JAR itself).
EDIT There is a caveat, though: Maven ignores JARs with scope=system for many operations. See also: How to include external jars in maven jar build process?
If Maven doesn't add the JAR to the output, then you must install all JARs with this scope into your local maven repo ($HOME/.m2/repository) using the mvn install:file-install command. See http://maven.apache.org/plugins/maven-install-plugin/usage.html how to do that.
Note: Installing libraries in your local repo is the preferred way; you should really consider it. For one, the scope=system will no longer confuse you (since many plugins handle them in a special way). Plus you need to do this only once. Afterwards, you can use this library in many Maven projects.
Before installing, you should check http://search.maven.org/ to see if the dependency isn't already known to Maven.
MySQL is: http://search.maven.org/#artifactdetails%7Cmysql%7Cmysql-connector-java%7C5.1.32%7Cjar
I am attempting to learn maven on a small project of my own, using eclipse. I converted the existing project to the maven standard directory configuration, and it was building; now I'm trying to get maven to produce the jar for the application. The following is pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion> 4.0.0 </modelVersion>
<groupId> com.rc </groupId>
<artifactId> SpaceCheck </artifactId>
<version> 0.9.1-SNAPSHOT </version>
<name> SpaceCheck </name>
<packaging> jar </packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId> org.apache.maven.plugins </groupId>
<artifactId>maven-jar-plugin </artifactId>
<version> 2.3.2 </version>
<configuration>
<includes>**/src/*</includes>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>spacecheck.SpaceCheck</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
I didn't use to have the 'includes' clause; as near as I can tell, that's what the example I got pointed to told me to do to fix the problem. It does not.
When I attempt to build, I get:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-jar-plugin:2.3.2:jar (default-jar) on
project SpaceCheck: Unable to parse configuration of mojo
org.apache.maven.plugins:maven-jar-plugin:2.3.2:jar for parameter
includes: Cannot assign configuration entry 'includes' with value
'*/src/' of type java.lang.String to property of type
java.lang.String[] -> [Help 1]
The "Help 1" link points me to the tutorial that I followed to get this far.
The problem I have with the tutorial is that it doesn't explain how things work -- it gives you an example and expects you to extract general workings from the example. There's nothing wrong with examples, but they rarely match exactly what one wants to do.
I'm sure many people can tell me what's wrong, and I would appreciate it. But it would be even better if they could ALSO tell me where this is explained, not just where there is an example that does something similar. The explanation, to be complete, would explain what element needs to be added, just where in the XML that goes, and what the various options are for the thing that goes there.
Instead of
<includes>**/src/*</includes>
try
<includes>
<include>**/src/*</include>
</includes>
And if you are learning Maven you definitely want to check out The Complete Reference.
Since you're asking for the documentation (and not the direct answer), have a look at http://maven.apache.org/guides/mini/guide-configuring-plugins.html
The problem is maven version
Following format for list/set is support in maven 3.3.9 and onward versions but in lower versions it not supported.
<includes>**/src/*</includes>
But in maven version less than 3.3.9, above is not supported
To fix make it backward compatible
<includes>
<include>**/src/*</include>
</includes>
PS: for more details check this link