How Do I Publish My Working Project (corresponding dot jar doesn'twork on other's PCs)


C

clusardi2k

Hello,

Once my NetBeans project is finalized what do I have to do to create an executable others can execute without having NetBeans directly installed on the computer.

Currently, my project contains a dot jav file which I can run to execute myproject. But, when others try to execute that same dot jar it doesn't work.. (Am I missing something here or should executing the dot jar always work.How should I troubleshoot this problem.)

Thank you,
 
Ad

Advertisements

A

Andreas Leitgeb

Once my NetBeans project is finalized what do I have to do to create an executable others can execute without having NetBeans directly installed on the computer.
Currently, my project contains a dot jav file which I can run to execute my project. But, when others try to execute that same dot jar it doesn't work. (Am I missing something here or should executing the dot jar always work. How should I troubleshoot this problem.)

Maybe a trivial question, but do they have Java installed?

(I mean, they shouldn't need netbeans, but they will need
at least a Java Runtime Environment (jre) to run jar files.)
 
J

John B. Matthews

Andreas Leitgeb said:
Maybe a trivial question, but do they have Java installed?

(I mean, they shouldn't need netbeans, but they will need
at least a Java Runtime Environment (jre) to run jar files.)

Java Web Start appears to address this on supported platforms in the
href provided to the version attribute of the j2se tag. I've never
actually tried it, as my platform vendor supplies the JRE.

<http://stackoverflow.com/tags/java-web-start/info>
 
N

Nigel Wade

Hello,

Once my NetBeans project is finalized what do I have to do to create an executable others can execute without having NetBeans directly installed on the computer.

Currently, my project contains a dot jav file which I can run to execute my project. But, when others try to execute that same dot jar it doesn't work. (Am I missing something here or should executing the dot jar always work. How should I troubleshoot this problem.)

Thank you,


What type of project did you create in NetBeans? Was it a Java
Application? Only this type of project creates the necessary manifest in
the project jar for it to be run simply by the java -jar project.jar
command. There are also some other constraints which if they are not met
will cause NetBeans to not create an "executable" jar. Offhand I cannot
remember what they are, and I've not had this problem re-occur for some
time.

A NetBeans Java Application should create a dist/ directory containing
the actual project jar, and a dist/lib directory containing any required
additional jars. It should also include an appropriate manifest in the
project jar which makes the jar "executable" (i.e. has a Main-Class
property). It also includes the lib/ directory in the jar Classpath.

Check the contents of your dist/ directory, and the project jar. If it
doesn't include these features then it's not a proper Java "application"
jar. That may mean that you didn't create it correctly, or NetBeans has
cocked up (technical term) the project properties (this does happen). If
this does happen the simplest alternative is to create a new Java
Application project and copy all your sources into it. Fixing it
manually requires dexterous manipulation of, IIRC, project.properties
and build-impl.xml. Creating a new project is simpler, quicker, and less
likely to bite you back in the future.
 
L

Lew

Nigel said:
What type of project did you create in NetBeans? Was it a Java
Application? Only this type of project creates the necessary manifest in

the project jar for it to be run simply by the java -jar project.jar

Not exactly. You can certainly edit the manifest in a normal JAR project or
normal Java project. I haven't worked with the "Java Application" NetBeans
project, but I've seen some complaints about it in this forum. Just set
"Main-Class:"

Read the Oracle site docs about JARs and JAR manifests. Your customers
can run JARs via Java WebStart, as mentioned, or directly by associating
"java -jar" with JAR files (might need "javaw -jar" on Windows platforms).

http://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html
command. There are also some other constraints which if they are not met
will cause NetBeans to not create an "executable" jar. Offhand I cannot
remember what they are, and I've not had this problem re-occur for some
time.

A NetBeans Java Application should create a dist/ directory containing
the actual project jar, and a dist/lib directory containing any required
additional jars. It should also include an appropriate manifest in the
project jar which makes the jar "executable" (i.e. has a Main-Class
property). It also includes the lib/ directory in the jar Classpath.

The manifest's "Class-Path:" header, which specifies paths relative
to the JAR location on the target system.
Check the contents of your dist/ directory, and the project jar. If it
doesn't include these features then it's not a proper Java "application"
jar. That may mean that you didn't create it correctly, or NetBeans has
cocked up (technical term) the project properties (this does happen). If
this does happen the simplest alternative is to create a new Java
Application project and copy all your sources into it. Fixing it
manually requires dexterous manipulation of, IIRC, project.properties
and build-impl.xml. Creating a new project is simpler, quicker, and less
likely to bite you back in the future.

You don't need to futz with NB-specific files if you edit manifests yourself,
and also you should build from "build.xml", not IDE-specific artifacts.
 
J

John B. Matthews

Check the contents of your dist/ directory, and the project jar. If
it doesn't include these features then it's not a proper Java
"application" jar. That may mean that you didn't create it
correctly, or NetBeans has cocked up (technical term) the project
properties (this does happen). If this does happen the simplest
alternative is to create a new Java Application project and copy
all your sources into it. Fixing it manually requires dexterous
manipulation of, IIRC, project.properties and build-impl.xml.
Creating a new project is simpler, quicker, and less likely to bite
you back in the future.

You don't need to futz with NB-specific files if you edit manifests
yourself, and also you should build from "build.xml", not
IDE-specific artifacts.[/QUOTE]

I like the flexibility NetBeans affords in this area:

For convenience, I can use the stock, NB-generated build.xml, even from
the command line, and hook into it as needed:

<http://stackoverflow.com/q/3955299/230513>

Alternatively, I can add a small number of targets to my custom
build.xml, and NB will happily adopt it in a free-form project:

<http://netbeans.org/kb/articles/freeform-config.html>

For example:

<https://sites.google.com/site/drjohnbmatthews/manifesto>
 
Ad

Advertisements

C

clusardi2k

Help, all I need is:

(1) the JDK (which one, The jars were created with NetBeans 7.1.2),

(2) put /dist/lib/*.jars" into my classpath environment variable, and

(3) possibly use "java -jar" and "javaw -jar"?

Thank you,
 
L

Lew

(unknown) said:
Help, all I need is:

(1) the JDK (which one, The jars were created with NetBeans 7.1.2),

That depends on how you have NetBeans and the particular project
configured.

Which JDK did you configure the project to use?
(2) put /dist/lib/*.jars" into my classpath environment variable, and

What? Huh?

You shouldn't be messing around with root-level
directories like that.

Put your project directory under your home directory or
in some suitable location like /projects/.
(3) possibly use "java -jar" and "javaw -jar"?

What do you mean?

The "-jar" parameter to those commands specifies a JAR
file for Java to run, if that's what you're asking.
 
C

clusardi2k

(unknown) wrote: > Help, all I need is: > > (1) the JDK (which one, The jars were created with NetBeans 7.1.2), That depends on how you have NetBeans and the particular project configured. Which JDK did you configure the project to use? > (2) put /dist/lib/*.jars" into my classpath environment variable, and What? Huh? You shouldn't be messing around with root-level directories like that. Put your project directory under your home directory or in some suitable location like /projects/. > (3) possibly use "java -jar" and "javaw -jar"? What do you mean? The "-jar" parameter to those commands specifies a JAR file for Java to run, if that's what you're asking. -- Lew

On NetBeans, how do I determine what JDK I'm using. I forgot which one I loaded.

Thanks,
 
M

markspace

On NetBeans, how do I determine what JDK I'm using. I forgot which
one I loaded.


It's in your project properties. And it's not the one you have loaded,
it's the one you have set for the build target. In other words, if you
are using JDK 7, you can still be targeting for example Java 5 in your
project, which is useful if you have users still on Java 5 who don't
want to upgrade.

Right-click on the project, Properties -> Sources, way down at the
bottom it says "Sources/Binary Format", that's your target (I'm using NB
7.2 btw, I seem to remember a slightly different option format in NB 6).

Also, you need the JRE. The JDK is for development, your users won't
normally need that. All they need is the normal runtime, the JRE. You
personally can use the JDK, because it contains a JRE, but anyone else
will normally just have the JRE.

To run, you use java -cp <path to all needed jars> -jar <path/your jar>

If you need to do fancier things than that (distribute over the
internet, for example) then look into Java WebStart or consider OneJar
if you are going to just copy the files around.
 
Ad

Advertisements

L

Lew

markspace said:
To run, you use java -cp <path to all needed jars> -jar <path/your jar>

The problem with that is that the command will ignore the "-cp" parameter.

"-cp" and "-jar" is either/or proposition.
 
M

markspace

The problem with that is that the command will ignore the "-cp" parameter.

"-cp" and "-jar" is either/or proposition.


Yes I totally forgot about that. I guess I don't actually run java from
the command line very often.

That leaves setting the classpath in the jar itself, which is kind of
tricky if you are going to be moving the jar to other people's
computers. Java WebStart and OneJar come in handy here.

Classpath in a jarfile:

<http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html>
 
C

clusardi2k

On 9/11/2012 5:12 AM, ... wrote: > On NetBeans, how do I determine what JDK I'm using. I forgot which > one I loaded. It's in your project properties. And it's not the one you have loaded, it's the one you have set for the build target. In other words, if you are using JDK 7, you can still be targeting for example Java 5 in your project, which is useful if you have usersstill on Java 5 who don't want to upgrade. Right-click on the project, Properties -> Sources, way down at the bottom it says "Sources/Binary Format",that's your target (I'm using NB 7.2 btw, I seem to remember a slightly different option format in NB 6). Also, you need the JRE. The JDK is for development, your users won't normally need that. All they need is the normal runtime, the JRE. You personally can use the JDK, because it contains a JRE,but anyone else will normally just have the JRE. To run, you use java -cp <path to all needed jars> -jar <path/your jar> If you need to do fancier things than that (distribute over the internet, for example) then look into Java WebStart or consider OneJar if you are going to just copy the files around.

How do I determine the specific JRE that I need.

Thanks,
 
M

markspace

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

How do I determine the specific JRE that I need.


Reading the replies you get on this newsgroup would be a good start.
 
C

clusardi2k

On 9/11/2012 11:08 AM, Lew wrote: > markspace wrote:
That leaves setting the classpath in the jar itself, which is kind of tricky if
you are going to be moving the jar to other people's computers. Java WebStart
and OneJar come in handy here. Classpath in a jarfile:
<http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html>

I just saw this article on the Internet. My guess is I should ignore this article, right?

http://ac-support.europe.umuc.edu/~arnoldyl/NetBeansTutorials/Setting-Classpath.html

Thanks,
 
Ad

Advertisements

C

clusardi2k

I added the path to all my dot jars into an environment variable (user varianble and not a system variable) called classpath and was unable to run the project. I mean nothing happened.

Via the Control Panel, I have the following programs installed on my friend's computer:

Java 7 Update 7
Java SE Development Kit 7 Update 7
Java(TM) 6 Update 34
Java(TM) 6 Update 34 (64-bit)

What's up? What do I do.

Thank you,
 
M

markspace

I added the path to all my dot jars into an environment variable
(user varianble and not a system variable) called classpath and was
unable to run the project. I mean nothing happened.

Learn to debug. Add some print statements so you can trace the
execution of your program. Attach a debugger.

If nothing happens, that's because your app did nothing. Java will
print an error message if it finds a problem.
 
C

clusardi2k

Learn to debug. Add some print statements so you can trace the execution of
your program. Attach a debugger. If nothing happens, that's because your app
did nothing. Java will print an error message if it finds a problem.

I added the following as the first executable statement (etc) in the project:

System.out.println("Hello 1");

I then ran the project on my friend's PC using the Command Prompt and the command: java testing.jar

I received the error message:

Exception in thread "main" java.lang.NoClassDefFoundError: testing/jar
Caused by: java.lang.ClassNotFoundException: testing.jar
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: testing.jar. Program will exit.

Thank you,
 
Ad

Advertisements

C

clusardi2k

On my own PC under NetBeans, I have no problem. I see the following from five print statements!

init:
Deleting: C:\testing\build\built-jar.properties
deps-jar:
Updating property file: C:\testing\build\built-jar.properties
files are up to date
compile:
run:
Hello 1
Hello 2
Hello 3
Hello 4
Hello 5
BUILD SUCCESSFUL (total time: 19 seconds)

Thank you,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top