View Full Version : JAVA: creazione .jar da NetBeans su UBUNTU
Ciao ragazzi,
come da oggetto, ho problemi nel creare un .jar eseguibile della mia applicazione JAVA.
Ho letto le guide in giro ma non ci sono riuscito.:muro:
Il contenuto del mio file manifest.mf è il seguente:
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
Ho poi provato così:
Dalla dir del manifest.mf da terminale:
jar cvfm gtm.jar /home/davix/NetBeansProjects/GTM/manifest.mf .
java -jar gtm.jar
ma mi restituisce quest'errore:
Exception in thread "main" java.lang.NoClassDefFoundError: /home/davix/NetBeansProjects/GTM/src/gtm/Start/form
Caused by: java.lang.ClassNotFoundException: .home.davix.NetBeansProjects.GTM.src.gtm.Start.form
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:336)
Could not find the main class: /home/davix/NetBeansProjects/GTM/src/gtm/Start.form. Program will exit.
Ho provato ad aggiungere nel manifest.maf la riga
Main-Class: /home/davix/NetBeansProjects/GTM/src/gtm/Start.form
All'interno della cartella /home/davix/NetBeansProjects/GTM/ io ho le cartelle:
build, dist, nbproject, src, test
e i file:
build.xml, manifest.mf e due file che vengono creati dall'applicazione
Questa è la mia situazione. Qualcuno mi sa dare una mano?:help:
Mi serve perché vorrei far vedere la mia applicazione (sia su UBUNTU e sia su WIndows) senza dover compilarla ogni volta da terminale o aprire l'IDE.
Grazie a tutti in anticipo.
Se premi "clean and build" (pulsante col martello e la scopetta) Netbeans dovrebbe creare automaticamente il jar eseguibile proprio nella cartella "dist".
Oceans11
30-09-2009, 12:22
a parte che netbeans, se non vado errato, dovrebbe creare il file jar automaticamente ad ogni build...
...tu sbagli qui:
Main-Class: /home/davix/NetBeansProjects/GTM/src/gtm/Start.form
cos'è Start.form?? e qual'è il tuo package? suppongo solo gtm e non home.davix.NetBeansProject.GTM.src.gtm, giusto?
in realtà dovresti fare:
Main-Class: MyPackage.MyClass
e ricordati di lasciare un paio di righe vuote alla fine del file.
[Modifica]: azz...c'ho messo 13minuti a scrivere questo post :)
Se premi "clean and build" (pulsante col martello e la scopetta) Netbeans dovrebbe creare automaticamente il jar eseguibile proprio nella cartella "dist".
Ho provato ma non lo crea. Anzi non c'è più la cartella "dist".
Devo mettere qualche opzione nell'IDE???
a parte che netbeans, se non vado errato, dovrebbe creare il file jar automaticamente ad ogni build...
...tu sbagli qui:
cos'è Start.form?? e qual'è il tuo package? suppongo solo gtm e non home.davix.NetBeansProject.GTM.src.gtm, giusto?
in realtà dovresti fare:
Main-Class: MyPackage.MyClass
e ricordati di lasciare un paio di righe vuote alla fine del file.
[Modifica]: azz...c'ho messo 13minuti a scrivere questo post :)
Ho provato a scrivere:
Main-Class: gtm.Start.java
e anche
Main-Class: gtm.Start
ma il risultato è sempre questo:
Could not find the main class: gtm.Start. Program will exit.
Altre idee??
Grazie mille
Se non crea la cartella dist allora ha incontrato qualche errore durante la compilazione.
Se non crea la cartella dist allora ha incontrato qualche errore durante la compilazione.
L'applicazione non ha errori e quando termina il processo mi dice:
clean:
init:
deps-jar:
Created dir: /home/davix/NetBeansProjects/GTM/build/classes
Created dir: /home/davix/NetBeansProjects/GTM/build/empty
Compiling 28 source files to /home/davix/NetBeansProjects/GTM/build/classes
compile:
COSTRUITO CON SUCCESSO (tempo totale: 6 secondi)
Vai nella scheda "files" a sinistra (dove c'è anche projects), espandi il file "build.xml", dovrebbe esserci un target di nome "jar". Se c'è, click col destro e seleziona "run target".
C'è?
Vai nella scheda "files" a sinistra (dove c'è anche projects), espandi il file "build.xml", dovrebbe esserci un target di nome "jar". Se c'è, click col destro e seleziona "run target".
C'è?
Il file non è cliccabile. L'ho aperto con Firefox che in alto mi dice:
"Il file XML specificato apparentemente non ha un foglio di stile associato. L'albero del documento è mostrato di seguito."
e poi giù c'è questo:
−
<!--
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.)
-->
−
<!--
By default, only the Clean and Build commands use this build script.
-->
−
<!--
Commands such as Run, Debug, and Test only use this build script if
-->
−
<!--
the Compile on Save feature is turned off for the project.
-->
−
<!--
You can turn off the Compile on Save (or Deploy on Save) setting
-->
<!-- in the project's Project Properties dialog box.-->
−
<project name="GTM" default="default" basedir=".">
<description>Builds, tests, and runs the project GTM.</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="GTM-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.
-->
</project>
Che hai, il Netbeans della mutua?
Pigia qui:
http://www.tukano.it/netbeans.jpg
Che hai, il Netbeans della mutua?
Beh un pò è vero che "lo passa la mutua" ...visto che è GRATIS!!!
Comunque, non avevo pensato a farlo dall'interno dell'IDE....
L'ho fatto e questo è il risultato:
Created dir: /home/davix/NetBeansProjects/GTM/dist
Building jar: /home/davix/NetBeansProjects/GTM/dist/GTM.jar
Not copying the libraries.
To run this application from the command line without Ant, try:
java -jar "/home/davix/NetBeansProjects/GTM/dist/GTM.jar"
jar:
COSTRUITO CON SUCCESSO (tempo totale: 7 secondi)
Comunque il jar è stato creato. Solo che ora non riesco ad eseguirlo con UBUNTU.
Con cosa lo eseguo? Ho provato con:
jar
javac
Sun Java 6 runtime
OpenJDK Java 6 Runtime
OpenJDK Java 6 Web Start
ma non va. Mi manca qualcosa che devo installare??? O è quel "Not copying the libraries." che non me lo fa eseguire?
Garzie
Ce ne fossero di gratis come Netbeans! :)
il "not copying the libraries" te lo da perchè il progetto non richiede librerie non standard. Se ce ne fossero l'ide creerebbe una cartella "lib" nella cartella "dist" e metterebbe lì dentro altra roba.
Per l'esecuzione prova a seguire il consiglio del buon Netbean:
To run this application from the command line without Ant, try:
java -jar "/home/davix/NetBeansProjects/GTM/dist/GTM.jar"
Si può anche lanciare il programma con un doppio click sul jar SE i file jar sono associati all'eseguibile java.
E' un po' che non uso più un linux ma ricordo che con KDE si potava cliccare col destro sul file jar, scegliere qualcosa tipo "associazione file" e specificare una cosa tipo "esegui da console con il comando...". Là mettevi "java -jar" e il gioco era fatto. Ma sono ricordi di un tot di anni fa.
Infatti volevo sapere se c'era un modo per evitare di aprire il Terminale e digitare il comando.
Ho provato a fare in UBUNTU (GNOME):
APRI CON --> Use a custom command
Ho inserito "java -jar" (senza virgolette, poi con e poi con apici)ma non mi prende l'opzione -jar e quindi lo esegue solo con il comando java che ovviamente non funziona.
Googlando non ho trovato nulla. Se qualcuno sa qualcosa è il benvenuto...
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.