Reputation: 501
I have an application written in Java that uses Maven to build. I'd like to deploy it using JNLP. This is the folder structure I have:
MyProject
├── pom.xml
├── src
│ ├── main
│ │ ├── java
│ │ │ ├── folder
│ │ │ │ ├── to
│ │ │ │ │ ├── my
│ │ │ │ │ │ ├── project
│ │ │ │ │ │ │ ├── ClassWithMain.java
│ │ ├── jnlp
│ │ │ ├── myjnlp.jnlp
│ │ │ ├── myjar.jar
│ │ │ ├── mymanifest.txt
│ │ │ ├── keystore
│ │ │ ├── pageToLaunchJnlp.html
├── target
│ ├── classes
│ │ ├── folder
│ │ │ ├── to
│ │ │ │ ├── my
│ │ │ │ │ ├── project
│ │ │ │ │ │ ├── ClassWithMain.class
I created the jar using mymanifest.txt and the ClassWithMain.class from within the target folder, and I signed it using the keystore and a timestamp url.
There are other files besides ClassWithMain, but that's the one with the main method.
But when I try to run the jnlp file, I get the error:
java.lang.ClassNotFoundException: folder.to.my.project.ClassWithMain
at java.net.URLClassLoader.findClass(Unknown Source)
at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.sun.jnlp.JNLPClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Here's my jnlp file below. I took out the codebase attribute since I saw the tutorial of deploying without a codebase at this link. My HTML file uses the launchWebStartApplication and createWebStartLaunchButtonEx functions, but I still get the ClassNotFoundException.
I've tried changing it to main.java.folder.to.my.project.ClassWithMain
, but that doesn't work either.
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0"
href="myjnlp.jnlp">
<information>
<title>My Project</title>
<description>My Project Webstart</description>
<offline-allowed/>
</information>
<security>
<sandbox/>
</security>
<resources>
<j2se href="http://java.sun.com/products/autodl/j2se" version="1.6+" initial-heap-size="512m"
max-heap-size="512m"/>
<property name="sun.java2d.noddraw" value="true"/>
<jar href="myjar.jar" main="true"/>
</resources>
<application-desc main-class="folder.to.my.project.ClassWithMain"/>
</jnlp>
Here's where my ClassWithMain is located according to the jar tvf
command:
Users/myusername/MyProject/target/classes/folder/to/my/project/ClassWithMain.class
Is this an issue with my folder structure, and if so, what is the correct structure/location for the jnlp file, jar file, keystore, etc. so the main class file is detected properly?
Thanks, any help is appreciated.
Upvotes: 2
Views: 545
Reputation: 1070
Your folder structure should be like this -
MyProject
├── pom.xml
├── src
│ ├── main
│ │ ├── java
│ │ │ ├── folder
│ │ │ │ ├── to
│ │ │ │ │ ├── my
│ │ │ │ │ │ ├── project
│ │ │ │ │ │ │ ├── ClassWithMain.java
resources
├── folder
│ ├── to
│ │ ├── my
│ │ │ ├── project
├── myjnlp.jnlp
├── myjar.jar
├── mymanifest.txt
├── keystore
├── pageToLaunchJnlp.html
you will get
├── target
│ ├── classes
│ │ ├── folder
│ │ │ ├── to
│ │ │ │ ├── my
│ │ │ │ │ ├── project
│ │ │ │ │ │ ├── ClassWithMain.class
├── myjnlp.jnlp
├── mymanifest.txt
├── pageToLaunchJnlp.html
At the run time myjnlp.jnlp will get ClassWithMain.class at same location. And yes I doubt about your jar location it should not be where you were showing, second think keystore, why you need to keep in build ? if you need it should be move to meta-inf of your build.
Upvotes: 1