ClassNotFoundException Netbeans Maven Library wrapper - maven

I was able to follow the tutorial here and convert it to a Maven application.
I got the loading part right, but when I try to use it, it can't find the appropriate swt classes (When ran from windows 64). I did it on a Maven project. Here's the relevant part of the respective pom for the Windows 64 module:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>nbm-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<!-- To have the jar plugin pickup the nbm generated manifest -->
<useDefaultManifestFile>true</useDefaultManifestFile>
<moduleType>normal</moduleType>
swt.windows.64/1</codeNameBase>
<publicPackages>
<publicPackage>org.eclipse.swt</publicPackage>
</publicPackages>
</configuration>
</plugin>
I translates to org.eclipse.swt.*. It seems to be a Maven module issue since it already tries to load from correct module.
Caused: java.lang.ClassNotFoundException: org.eclipse.swt.SWT starting from ModuleCL#25e0dee5[djproject.core] with possible defining loaders [ModuleCL#6783113b[swt.windows.64]] and declared parents [ModuleCL#32821bf7[org.netbeans.api.annotations.common]]
Caused: java.lang.NoClassDefFoundError: org/eclipse/swt/SWT
at chrriis.dj.nativeswing.swtimpl.core.SWTNativeInterface.initialize_(SWTNativeInterface.java:213)
at chrriis.dj.nativeswing.swtimpl.NativeInterface.initialize(NativeInterface.java:71)
at chrriis.dj.nativeswing.swtimpl.core.SWTNativeInterface.open_(SWTNativeInterface.java:337)
at chrriis.dj.nativeswing.swtimpl.NativeInterface.open(NativeInterface.java:100)
at synamicd.windows64.support.Windows64BrowserProvider.initialize(Windows64BrowserProvider.java:25)
Any help is more than welcomed!
Edit:
Code is available here.

when I try to build the application at the bitbucket location, it's build order suggests that none of the swt modules are used in the app - http://screencast.com/t/LMxIPy6A6ZUL

Related

Include and use native lib files (.so, .dylib) in "executable JAR"

I have a multimodule Spring Boot project with Maven. I am using spring-boot-maven-plugin to package this application into an executable JAR. This JAR is deployed to PCF (Pivotal Cloud Foundry).
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>my.AppMain</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
Now I would like to use PDFTron library - they provided me with a JAR ,.so and .dylib files (.dll too but I dont need those). They said that the JAR has to be in the same directory as the so and dylib files in order to work properly.
I tried to use this library in the project but I cant make it work. I am running out of ideas, I believe I have read almost all possible posts to this topic.
I have tried:
load each of this files to maven repo, include each one as (dylib, so and pdfnet.jar), but it resulted in error message: Caused by: java.lang.UnsatisfiedLinkError: no PDFNetC in java.library.path:
put all the files (dylib, so and pdfnet.jar) into the src/main/resources, include just provided PDFNet.jar as but it resulted in error message: Caused by: java.lang.UnsatisfiedLinkError: no PDFNetC in java.library.path:
Only way that worked was when I used maven-dependency-plugin to unpack the PDFTron dependencies into the target directory and update the -Djava.library.path to point at this created directory - but this can be done only at my local machine, because PDFTron dependencies were unpacked at "package" phase. To the PCF we are depolying only the executable JAR, so there is no target directory at PCF, so this was not an "production ready" option.
My question is, how can I include these files into this "executable JAR" so it will work properly ? Is there a way to unpack them at runtime ? Or do I have to use other plugin than spring-boot-maven-plugin ?
I can modify the -Djava.library.path at PCF, but I would like to avoid deploying another zip/jar/folder along with this JAR (basically I want to avoid changing the CI/CD deploy script as it is not under my control - and right now we are deploying only the executable JAR)
I am using java version "11.0.8" and spring-boot version "2.2.8.RELEASE"
You only need two files, per-platform.
PDFNet.jar is for all platforms.
libPDFNetC.so for Linux
PDFNetC.dll for Windows
PDFNetC.dylib for macOS
You can see in the samples, there are RuntTest.[sh|exe] files that show the settings that you can use. For example
#!/bin/sh
TEST_NAME=AddImageTest
javac -cp ../../../Lib/PDFNet.jar *.java
java -Djava.library.path=../../../Lib -cp .:../../../Lib/PDFNet.jar $TEST_NAME
So -Djava.library.path= points to the folder containing libPDFNetC.so and/or PDFNetC.dll.
It sounds like you have deployment specific issue with your tech stack, but I assume there is a way, same as how you would deploy any images/fonts or other resources. Though maybe your tech stack puts some restrictions on where java.library.path can point to, but that should be in the documentation supplied by what you are using.

NetBeans - show compiler warnings for JSP in non-standard location

Modular components for Liferay portal provided as OSGi modules use non standard Maven layout. All JSP pages are located in /src/main/resources/META-INF/resources instead of typical /src/main/webapps. Moreover, jar packaging is used instead of typical war. When such a project is opened in NetBeans, no errors or warnings are shown in JSP file even it is broken deliberately.
Example project can be found here https://github.com/liferay/liferay-blade-samples/tree/7.1/maven/apps/jsp-portlet
Can I somehow configure NetBeans to process my JSP files as usual?
NetBeans source code revealed there is some support for non-standard locations via the configuration of maven-war-plugin. So this plugin has to be present even not needed for the build:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<warSourceDirectory>/src/main/resources/META-INF/resources</warSourceDirectory>
</configuration>
</plugin>

Java 11 Eclipse finds automatic module, Maven does not

I'm attempting to upgrade a 15 year old Maven multimodule project to Java 11, and the module system that was introduced in Java 9. Since the project is built using Maven, all dependencies are pretty clear. First I want to do this using the automatic module names, in order not to also introduce upgraded artifacts (if not absolutely required).
Eclipse is pretty helpful in this process, autocompleting the automatic module names in the module-info.java. For example:
requires dom4j;
But if I compile with Maven, I get errors about that it cannot find the modules Eclipse just autocompleted in there.
module-info.java:[29,18] module not found: dom4j
I am using Maven's compiler plugin 3.7.0 (3.8.0 gives a NullPointerException as per https://jira.apache.org/jira/browse/MCOMPILER-355) I suspect Maven is setting the jars up on the classpath instead of on the modulepath, but the compiler's plugin debug output does not log that.
How can I make Maven correctly handle those modules?
I was running into the same issue. Adding
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
</plugins>
</build>
to my pom solved the problem for me...
Maven version 3.9.0 seems to be buggy and will not find the module although the dependency is using an Automatic-Module-Name. Downgrading to version 3.8.1 helps.

Deploying Maven project to JBoss AS7 (standalone)

I am new to JBOSS AS7, and am strictly using MAVEN 3 via command line. I would like to deploy the *.war of my project to JBOSS AS7 without ECLIPSE. I have spent couple of days Googling and trying out difference approaches. I am able to deploy the *.war to Tomcat. I would highly appreciate any help on this. So far this is what I have done:
I have entered the server info(Jboss) to C:\maven\conf\settings.xml
I have included the plugin to the POM
I think I may be declaring the path to JBoss AS7 within my JBOSS plugin wrong.
This is how I am including the plugin in the POM file:
<plugins>
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.0.2.Final</version>
<configuration>
<url>http://localhost:8080/
<server>jboss</server>
<path>/web-app</path>
<configuration>
</plugin>
</plugins>
Did you have a look at the README on the corresponding GitHub page:
https://github.com/jbossas/jboss-as-maven-plugin
When deploying to your localhost (which is the default value) you don't need to define the <url> in the <configuration>, as well as the <server> and <path> elements (besides: I haven't seen a folder named wep-app in AS7).
We run a project where this works even without touching the settings.xml.
So when you have checked this, post what exactly goes wrong, what is the concrete failure message and what is the maven command you use (mvn jboss-as:deploy).

Where should a custom Netbeans Platform conf. file be so that maven finds it?

Applications built on top of the NetBeans platform have a <myappdir>/etc/<myapp>.conf file determining, among other things, application JVM parameters. Historically, this file was a part of the NetBeans IDE installation (as far as I could tell), but starting with NB 6.9, custom files are now supported.
I am having trouble packaging a custom configuration file using Maven to build the application.
I imagine the app.conf property should have been set in the project's pom under project/build/pluginManagement/plugins like so:
<plugin>
...
<configuration>
<brandingToken>${brandingToken}</brandingToken>
<cluster>${brandingToken}</cluster>
<appConf>myapp.conf</appConf>
</configuration>
The maven module representing my application contained no prior source, so I created the src/main/nbm folder and placed myapp.conf in src/main/nbm. This isn't picked up by nbm-maven-plugin. and putting the conf file into src/main/resources doesn't make a difference.
So, can anyone explain how a NetBeans Platform application with a custom configuration file can be built using maven?
UPDATE:
With Tim's prod in the right direction, I found the answer documented on Geertjan's blog. The solution is to configure the nbm-maven-plugin like so in the application module pom:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>nbm-maven-plugin</artifactId>
<configuration>
<etcConfFile>src/main/resources/my.conf</etcConfFile>
</configuration>
</plugin>
</plugins>
</build>
BTW, if you need a second name with Geertjan, you're not really a NetBeans platform developer. ;)
Have a look at the documentation of the nbm:cluster-app plugin, specifically the part on the conf file.
As per my understanding that should allow you to replace the default one with a custom one that you create.

Resources