[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 852
  • Last Modified:

Java Netbeans with Web Start: Deploying an app to an Apache Web Server

I am working with Netbeans IDE 5.5.1 and Web Start on Windows XP to deploy a Java Application to an Apache Web Server on Linux. First of all I am a coder but Im not very familiar with Netbeans IDE or Web Start. I see that by right clicking on the name in the projects tab I can choose Java Web Start and Deploy with Java Web Start. This creates the necessary files for deployment (I guess, let me know if Im wrong) and says Deploying app to server then creates a JSP page on my localhost with a button.

What I am trying to do is deploy the app to Apache on a Linux server I have set up on the network. I think I understand the JNLP file enough:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jnlp PUBLIC "-//Sun Microsystems, Inc.//DTD JNLP 1.5//EN" "http://www.netbeans.org/jnlp/DTD/jnlp.dtd">
<jnlp codebase="$$codebase" href="Contacts.jnlp">
  <information>
    <title>Contacts</title>
    <vendor>MyCompany, Inc.</vendor>
    <homepage href="http://www.mycompany.com"/>
    <description>Contact Information</description>
    <icon href="default"/>
    <offline-allowed/>
    <shortcut online="true">
    </shortcut>
  </information>
  <resources>
    <j2se href="http://java.sun.com/products/autodl/j2se" version="1.4+"/>
  </resources>
  <resources>
    <jar href="dist/Contacts.jar" main="true"/>`
  </resources>
  <application-desc main-class="my.contacts.ContactsUI"/>
</jnlp>

I guess this is the link to download the files <jnlp codebase="$$codebase" href="Contacts.jnlp">

But I don't know where to set the server to deploy to. I guess it would ask for the host, login and password.

I'm sure exactly sure what question I should ask so I hope someone understands what I mean.

And Thanks!
0
SaltyDawg
Asked:
SaltyDawg
  • 20
  • 16
1 Solution
 
CEHJCommented:
This is how i do it - by customizing the Ant build.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<project name="yyy" default="default" basedir=".">
    <description>Builds, tests, and runs the project yyy.</description>
    <import file="nbproject/build-impl.xml"/>
    <!--

    There exist several targets which are by default empty and which can be
    used for execution of your tasks. These targets are usually executed
    before and after some main targets. They are:

      -pre-init:                 called before initialization of project properties
      -post-init:                called after initialization of project properties
      -pre-compile:              called before javac compilation
      -post-compile:             called after javac compilation
      -pre-compile-single:       called before javac compilation of single file
      -post-compile-single:      called after javac compilation of single file
      -pre-compile-test:         called before javac compilation of JUnit tests
      -post-compile-test:        called after javac compilation of JUnit tests
      -pre-compile-test-single:  called before javac compilation of single JUnit test
      -post-compile-test-single: called after javac compilation of single JUunit test
      -pre-jar:                  called before JAR building
      -post-jar:                 called after JAR building
      -post-clean:               called after cleaning build products

    (Targets beginning with '-' are not intended to be called on their own.)

    Example of inserting an obfuscator after compilation could look like this:

        <target name="-post-compile">
            <obfuscate>
                <fileset dir="${build.classes.dir}"/>
            </obfuscate>
        </target>

    For list of available properties check the imported
    nbproject/build-impl.xml file.


    Another way to customize the build is by overriding existing main targets.
    The targets of interest are:

      -init-macrodef-javac:     defines macro for javac compilation
      -init-macrodef-junit:     defines macro for junit execution
      -init-macrodef-debug:     defines macro for class debugging
      -init-macrodef-java:      defines macro for class execution
      -do-jar-with-manifest:    JAR building (if you are using a manifest)
      -do-jar-without-manifest: JAR building (if you are not using a manifest)
      run:                      execution of project
      -javadoc-build:           Javadoc generation
      test-report:              JUnit report generation

    An example of overriding the target for project execution could look like this:

        <target name="run" depends="yyy-impl.jar">
            <exec dir="bin" executable="launcher.exe">
                <arg file="${dist.jar}"/>
            </exec>
        </target>

    Notice that the overridden target depends on the jar target and not only on
    the compile target as the regular run target does. Again, for a list of available
    properties which you can use, check the target you are overriding in the
    nbproject/build-impl.xml file.

    -->
    <!-- Do we *really* have to use this kludge to stop deletion of the config
    file during a clean? -->
    <target name="-post-init">
        <copy file="config/log4j.xml" todir="build/classes" />
    </target>
   
    <target name="-post-jar">
        <antcall target="sign" />
        <antcall target="restore-jnlp" />
        <antcall target="deploy" />
    </target>
   
    <target name="restore-jnlp"
            description="Config of the security details seems to be broken,
    so we need to restore the proper launch.jnlp from backup ">
        <copy todir="dist" file="backup\launch.jnlp" overwrite="true" />
    </target>
   
    <target name="sign">
        <signjar description="Sign the jars for JWS - IDE's seems to be broken"
                 keystore="${user.home}/.keystore"
                 storepass="ggggg"
                 alias="alias">
                 <!--
                <fileset dir="." includes="dist/yyy.jar" />
                <fileset dir="." includes="dist/lib/Protean.jar" />-->
                <fileset dir="." includes="**/*.jar" />
        </signjar>
    </target>
   
    <target name="deploy">

        <scp
            todir="goose@xxx.net:/var/www/vvv.net/docs/jws/yyy"
            passphrase="something"
            keyfile="C:/cygwin/home/Charles/.ssh/id_rsa"
            trust="yes"
            verbose="true">
           
            <fileset dir=".">
                <include name="dist/**/*.jar" />
                <include name="dist/lib/Protean.jar" />
                <include name="dist/yyy.jar" />
                <include name="dist/launch.*" />
            </fileset>
        </scp>
    </target>
   
</project>
0
 
SaltyDawgAuthor Commented:
During developnment where exactly do I set the FTP access in order to upload the file the server in Netbeans for Web Start. Currently it's all set to go to the localhost, but I would like to set it to go to another PC with Linux and Apache Web Server installed.

Thanks.
0
 
CEHJCommented:
Well you can see i'm using scp (more secure), not ftp, but if you want to use ftp instead then choose that Ant task, e.g.

      <ftp
            server="www.someone.uklinux.net"
            remotedir="/jws"
            userid="xxxx"
            password="yyyy"
            action="put"
            verbose="yes"
      >

            <fileset dir=".">
                <include name="dist/**/*.jar" />
                <include name="dist/lib/Protean.jar" />
                <include name="dist/xxx.jar" />
                <include name="dist/launch.*" />
            </fileset>
            
      </ftp>
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
SaltyDawgAuthor Commented:
Thanks for the info. I am using FTP because I'm using a local network that will not be connected the internet. The only access will be in house employees. I'm trying to take an existing Java App which is installed on various Production PCs and use Java Web Start to automatically update those apps. So no real need to secure it from the Internet because it will never be connected.

I'll try this out tomorrow when I get t o work. Thanks.
0
 
SaltyDawgAuthor Commented:
The truth is, I am not very familiar with Web Start, JNLP, ANT or much else associated with this.

I have read about the JNLP file and notice its used so the end user can download the files from the specified location. Though I do not know much about customizing the Ant build.xml. I am using Netbeans right now (and actually just started using it). So I ma pretty much lost as to want I need to do to deploy this app using Web Start. Some detailed step by step help would be greatly appreciated.
0
 
CEHJCommented:
There's not much to it other than what i said. The build.xml file is already part of your project
0
 
SaltyDawgAuthor Commented:
I think I am begining to understand a little. I am having trouble with the Target tags specifically the "-post-init" "-post-jar".

    <target name="-post-init">
        <copy file="config/log4j.xml" todir="build/classes" />
    </target>
   
    <target name="-post-jar">
        <antcall target="sign" />
        <antcall target="restore-jnlp" />
        <antcall target="deploy" />
    </target>

Not sure exactly what changes need to be made to this. Thanks
0
 
CEHJCommented:
Don't worry about the first one if you're not using log4j. IOW it can go altogether if you're not. The other can have the first 2 antcall removed
0
 
SaltyDawgAuthor Commented:
Ok I am using scp to transfer a copy to the linux server. I think I have the "todir":
        <scp
            todir="myusername:mypassword@http://myhostIP:/mydir"
            passphrase="mypsp"
            keyfile="C:/cygwin/home/Charles/.ssh/id_rsa"
            trust="yes"
            verbose="true">
           
            <fileset dir=".">
                <include name="dist/**/*.jar" />
                <include name="dist/lib/Protean.jar" />
                <include name="dist/yyy.jar" />
                <include name="dist/launch.*" />
            </fileset>
        </scp>

First, what is keyfile="C:/cygwin/home/Charles/.ssh/id_rsa" used for, is it thr jar directory on my system?

And in <fileset dir="."> is that where I list the jar files I want copied over?
0
 
CEHJCommented:
>>First, what is keyfile="C:/cygwin/home/Charles/.ssh/id_rsa" used for, is it thr jar directory on my system?

That's where you should keep your private key. If you're just using password authentication then you can ignore that.

>><fileset dir="."> is that where I list the jar files I want copied over?

The current directory. Your Netbeans paths (if not the filenames) should be the same
0
 
SaltyDawgAuthor Commented:
OK so <fileset dir="."> is basically the same as my Project Folder Location?
0
 
CEHJCommented:
Yep. That's where build.xml is
0
 
SaltyDawgAuthor Commented:
ok great, let me try alll this out and see what happens. And thanks for getting back with me so quickly, much appreciated.
0
 
SaltyDawgAuthor Commented:
Hey, now that I finally have that build.xml connecting to my Apache server, I am now having some other issues.

I can now transfer the files to my Apache Server but when I do I create an extra directory:

Trying to transfer files:
-chow_saw.jar
-chop_saw.jnlp
(not even sure if I need to add the JNLP file?)
To :/webstart/chop_saw/dist/

I add those successfully, but I also end up creating:
/webstart/chop_saw/dist/dist
And adding:
-chow_saw.jar
With it.
I might have an idea on that (see code below), but may need your help though.

Also I thought I knew what to do with the JNLP file and how to configure it, but apparently I am doing something wrong.

Heres my build.xml:

    <target name="-post-jar">
        <!--<antcall target="sign" />
        <antcall target="restore-jnlp" />-->
        <antcall target="deploy" />
    </target>
   
    <target name="deploy">

        <scp
            todir="username:pass@hostIP:/var/www/html/webstart/chop_saw"
            trust="yes"
            verbose="true">
           
            <fileset dir="C:\<dir>\Java\NetBeans_projects\chop_saw">
                <include name="dist/chop_saw.jar" />
                <include name="chop_saw.jnlp" />
            </fileset>
        </scp>
    </target>

And my chop_saw.jnlp:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jnlp PUBLIC "-//Sun Microsystems, Inc.//DTD JNLP 1.5//EN" "http://www.netbeans.org/jnlp/DTD/jnlp.dtd">
<jnlp codebase="$$codebase" href="chop_saw.jnlp">
  <information>
    <title>Chop Saw</title>
    <vendor>Ebtron, Inc.</vendor>
    <homepage href="http:www.ebtron.com"/>
    <description> </description>
    <icon href="default"/>
    <offline-allowed/>
    <shortcut online="true"/>
  </information>
  <security>
    <all-permissions/>
  </security>
  <resources>
    <j2se href="http://java.sun.com/products/autodl/j2se" version="1.4+"/>
  </resources>
  <resources>
    <jar download="eager" href=dist/chop_saw.jar" main="false"/>
  </resources>
  <application-desc main-class="Ebtron.chopSaw"/>
</jnlp>

Now I guess I am not understanding something on the codebase. Thought I should enter
codebase=http://hostIP:/var/www/html/webstart/chop_saw but it keeps going back to codebase="$$codebase", is it suppose to do that?
0
 
CEHJCommented:
>>Thought I should enter codebase=http://hostIP:/var/www/html/webstart/chop_saw

No - you need to enter the webroot. That's the server's actual path. Probably


codebase="/webstart/chop_saw"
0
 
SaltyDawgAuthor Commented:
actually that is what I meant. I did have http://hostIP/webstart/chop_start ins the jnlp file. But why does it keep going back to $$codebase?
0
 
CEHJCommented:
That's because the clean process erases the jnlp file. You need to see my restore thing, along with the comment i made in the build file
0
 
SaltyDawgAuthor Commented:
Sorry, I'm not understanding the restore-jnlp call.

I am clicking a link to the JNLP file directly from the server. However it is not downloading and installing the app. The files I have placed on the server are "chop_saw.jar" and "chop_saw.jnlp".

Do I have to create an installer or should Web Start install the jar files? Do I need to add any other files?

Each time I think I have it, I get stuck with something else that seems like it should be simple. I'm getting a bit discouraged now ;(

Thanks for your help
0
 
SaltyDawgAuthor Commented:
Here are my files

Build.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<project name="chop_saw" default="default" basedir=".">
    <description>Builds, tests, and runs the project chop_saw.</description>
    <import file="nbproject/build-impl.xml"/>
    <import file="nbproject/build-jaws-impl.xml"/>
    <!--

    There exist several targets which are by default empty and which can be
    used for execution of your tasks. These targets are usually executed
    before and after some main targets. They are:

      -pre-init:                 called before initialization of project properties
      -post-init:                called after initialization of project properties
      -pre-compile:              called before javac compilation
      -post-compile:             called after javac compilation
      -pre-compile-single:       called before javac compilation of single file
      -post-compile-single:      called after javac compilation of single file
      -pre-compile-test:         called before javac compilation of JUnit tests
      -post-compile-test:        called after javac compilation of JUnit tests
      -pre-compile-test-single:  called before javac compilation of single JUnit test
      -post-compile-test-single: called after javac compilation of single JUunit test
      -pre-jar:                  called before JAR building
      -post-jar:                 called after JAR building
      -post-clean:               called after cleaning build products

    (Targets beginning with '-' are not intended to be called on their own.)

    Example of inserting an obfuscator after compilation could look like this:

        <target name="-post-compile">
            <obfuscate>
                <fileset dir="${build.classes.dir}"/>
            </obfuscate>
        </target>

    For list of available properties check the imported
    nbproject/build-impl.xml file.


    Another way to customize the build is by overriding existing main targets.
    The targets of interest are:

      -init-macrodef-javac:     defines macro for javac compilation
      -init-macrodef-junit:     defines macro for junit execution
      -init-macrodef-debug:     defines macro for class debugging
      -init-macrodef-java:      defines macro for class execution
      -do-jar-with-manifest:    JAR building (if you are using a manifest)
      -do-jar-without-manifest: JAR building (if you are not using a manifest)
      run:                      execution of project
      -javadoc-build:           Javadoc generation
      test-report:              JUnit report generation

    An example of overriding the target for project execution could look like this:

        <target name="run" depends="chop_saw-impl.jar">
            <exec dir="bin" executable="launcher.exe">
                <arg file="${dist.jar}"/>
            </exec>
        </target>

    Notice that the overridden target depends on the jar target and not only on
    the compile target as the regular run target does. Again, for a list of available
    properties which you can use, check the target you are overriding in the
    nbproject/build-impl.xml file.

    -->
    <target name="-post-jar">
        <!--<antcall target="sign" />-->
        <antcall target="restore-jnlp" />
        <antcall target="deploy" />
    </target>
   
    <target name="restore-jnlp"
            description="Config of the security details seems to be broken,
    so we need to restore the proper launch.jnlp from backup ">
        <copy todir="dist/backup" file="chop_saw.jnlp" overwrite="true" />
    </target>
   
    <target name="deploy">
        <scp
            todir="user:pass@10.0.0.3:/var/www/html/webstart/chop_saw"
            trust="yes"
            verbose="true">
           
            <fileset dir="C:\Projects\Jimmy's Work\Java\NetBeans_projects\chop_saw">
                <include name="dist/chop_saw.jar" />
                <include name="dist/chop_saw.jnlp" />
            </fileset>
        </scp>
    </target>
</project>


---------------
chop_saw.jnlp

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jnlp PUBLIC "-//Sun Microsystems, Inc.//DTD JNLP 1.5//EN" "http://www.netbeans.org/jnlp/DTD/jnlp.dtd">
<jnlp codebase="$$codebase" href="chop_saw.jnlp">
  <information>
    <title>Chop Saw</title>
    <vendor>Ebtron, Inc.</vendor>
    <homepage href="http:www.ebtron.com"/>
    <description> </description>
    <icon href="default"/>
    <offline-allowed/>
    <shortcut online="true"/>
  </information>
  <security>
    <all-permissions/>
  </security>
  <resources>
    <j2se href="http://java.sun.com/products/autodl/j2se" version="1.4+"/>
  </resources>
  <resources>
    <jar download="eager" href="http://10.0.0.3/webstart/chop_saw/dist/chop_saw.jar" main="false"/>
    <jar download="eager" href="http://10.0.0.3/webstart/chop_saw/dist/chop_saw.jnlp"/>
  </resources>
  <application-desc main-class="Ebtron.chopSaw"/>
</jnlp>


Where am I going wrong! I keep getting "Launch File Error" "Unable to Launch the Specified Application"

Thanks
0
 
CEHJCommented:
>>Sorry, I'm not understanding the restore-jnlp call.

The restore-jnlp is to combat exactly the problem you're having. Each time you do a clean, the jnlp gets reconstructed from a template. The correct thing would probably be to set up the template such that the parameters, such as codebase, are correct.

As far as i could see at the time, there was a confusion over codebase - the local and remote codebase are obviously different, so i just made sure the correct jnlp was copied over each time - that's all restore-jnlp does
0
 
CEHJCommented:
>>        <copy todir="dist/backup" file="chop_saw.jnlp"

Did you create that directory?
0
 
SaltyDawgAuthor Commented:
That directory is on my system (in my project folder), but not on the server. should it be on the server?
0
 
SaltyDawgAuthor Commented:
This Web Start stuff is kicking my butt. I'm a straight up coder specifically C/C++. I rarely do Java and its been more than 2 years since I programmed in Java, so ofcourse you can understanding my inept knowledge in Web Start and Netbeans which I have never used before. We have a bunch of firmware programmers here, who are actually just electronics engineers and I have the most experience in actually application programming so I got stuck with this task. Thanks for your help, Im hoping to complete this today, hopefully I am close!
0
 
SaltyDawgAuthor Commented:
Should my codebase parameters be set as such <jnlp codebase="http://10.0.0.3/webstart/chop_saw/dist" href="chop_saw.jnlp">. If so I have done that, and that led me to believe that my restore-jnlp is incorrect:

    <target name="restore-jnlp"
            description="Config of the security details seems to be broken,
    so we need to restore the proper launch.jnlp from backup ">
        <copy todir="dist/backup" file="chop_saw.jnlp" overwrite="true" />
    </target>
0
 
CEHJCommented:
That can be

<jnlp codebase="/webstart/chop_saw/dist" href="chop_saw.jnlp">

actually. Make sure you've a copy of chop_saw.jnlp in the root

0
 
CEHJCommented:
(root of the project)
0
 
SaltyDawgAuthor Commented:
I yes I'm a copy in root of the project. This is the same directory as the build.xml and all my folder right?
0
 
CEHJCommented:
Yes, that's right
0
 
SaltyDawgAuthor Commented:
It appears it all seems to revolve around maintaining the url in the codebase

<jnlp codebase="/webstart/chop_saw/dist" href="chop_saw.jnlp">

Instead of

<jnlp codebase="$$codebase" href="chop_saw.jnlp">

--------------
chop_saw.jnlp
-------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jnlp PUBLIC "-//Sun Microsystems, Inc.//DTD JNLP 1.5//EN" "http://www.netbeans.org/jnlp/DTD/jnlp.dtd">
<jnlp codebase="http://10.0.0.3/webstart/chop_saw/dist" href="chop_saw.jnlp">
  <information>
    <title>Chop Saw</title>
    <vendor>Ebtron, Inc.</vendor>
    <homepage href="http:www.ebtron.com"/>
    <description> </description>
    <icon href="default"/>
    <offline-allowed/>
    <shortcut online="true"/>
  </information>
  <security>
    <all-permissions/>
  </security>
  <resources>
    <j2se href="http://java.sun.com/products/autodl/j2se" version="1.4+"/>
  </resources>
  <resources>
    <jar download="eager" href="dist/chop_saw.jar" main="false"/>
    <jar download="eager" href="dist/chop_saw.jnlp"/>
  </resources>
  <application-desc main-class="Ebtron.chopSaw"/>
</jnlp>

--------------
build.xml
-------------
    <target name="-post-jar">
        <!--<antcall target="sign" />-->
        <antcall target="restore-jnlp" />
        <antcall target="deploy" />
    </target>
   
    <target name="restore-jnlp"
            description="Config of the security details seems to be broken,
    so we need to restore the proper launch.jnlp from backup ">
        <copy todir="dist/backup" file="chop_saw.jnlp" overwrite="true" />
    </target>
   
    <target name="deploy">
        <scp
            todir="user:pass@10.0.0.3:/var/www/html/webstart/chop_saw"
            trust="yes"
            verbose="true">
           
            <fileset dir="C:\Projects\Jimmy's Work\Java\NetBeans_projects\chop_saw">
                <include name="dist/chop_saw.jar" />
                <include name="dist/chop_saw.jnlp" />
                <include name="dist/backup/chop_saw.jnlp" />
            </fileset>
        </scp>
    </target>
0
 
SaltyDawgAuthor Commented:
Ok almost got it. But now I am having problems launching the file. I get:
"Unsigned application requesting unrestricted access to system"

I can't seem to figure out how to configure the signjar
0
 
CEHJCommented:
>>I can't seem to figure out how to configure the signjar

What's the problem? Did you model it on my signjar?
0
 
SaltyDawgAuthor Commented:
I managed to figure out the signjar. But I never did find out what I was doing wrong about the jnlp codebase keep changing to $$codebase. However that's minor right now. I am using a work-around for that. After I deploy it with Webstart, I manually change the filename of the jnlp file then change the codebase. I still need to figure that out, but atleast I have the whole thing working now.
0
 
CEHJCommented:
>>But I never did find out what I was doing wrong about the jnlp codebase keep changing to $$codebase

Did you create the backup directory as i mentioned?
0
 
SaltyDawgAuthor Commented:
I have it now. I created the restore-jnlp backup directory. But I kept forgetting to put the correct file in that directory. I had the file with $$codebase in it. I didn't think about that, I just opened the file and noticed it.

Thanks for all your help. I'll close this out later today just to make sure I don't run into anymore problems.
0
 
CEHJCommented:
OK
0
 
SaltyDawgAuthor Commented:
Thanks CEH, for your help, and being the only one to help this past week.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 20
  • 16
Tackle projects and never again get stuck behind a technical roadblock.
Join Now