|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Member
Iscritto dal: Apr 2008
Messaggi: 81
|
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. ![]() Il contenuto del mio file manifest.mf è il seguente: Codice:
Manifest-Version: 1.0 X-COMMENT: Main-Class will be added automatically by build Dalla dir del manifest.mf da terminale: Codice:
jar cvfm gtm.jar /home/davix/NetBeansProjects/GTM/manifest.mf . Codice:
java -jar gtm.jar Codice:
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. Codice:
Main-Class: /home/davix/NetBeansProjects/GTM/src/gtm/Start.form 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? ![]() 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. |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Nov 2004
Città: Tra Verona e Mantova
Messaggi: 4553
|
Se premi "clean and build" (pulsante col martello e la scopetta) Netbeans dovrebbe creare automaticamente il jar eseguibile proprio nella cartella "dist".
__________________
Uilliam Scecspir ti fa un baffo? Gioffri Cioser era uno straccione? E allora blogga anche tu, in inglese come me! |
![]() |
![]() |
![]() |
#3 | ||
Senior Member
Iscritto dal: Sep 2005
Città: Torino
Messaggi: 606
|
a parte che netbeans, se non vado errato, dovrebbe creare il file jar automaticamente ad ogni build...
...tu sbagli qui: Quote:
in realtà dovresti fare: Quote:
[Modifica]: azz...c'ho messo 13minuti a scrivere questo post ![]()
__________________
"Se proprio dovete piratare un prodotto, preferiamo che sia il nostro piuttosto che quello di qualcun altro." [Jeff Raikes] "Pirating software? Choose Microsoft!" Ultima modifica di Oceans11 : 30-09-2009 alle 12:30. |
||
![]() |
![]() |
![]() |
#4 | ||
Member
Iscritto dal: Apr 2008
Messaggi: 81
|
Quote:
Devo mettere qualche opzione nell'IDE??? Quote:
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 |
||
![]() |
![]() |
![]() |
#5 |
Senior Member
Iscritto dal: Nov 2004
Città: Tra Verona e Mantova
Messaggi: 4553
|
Se non crea la cartella dist allora ha incontrato qualche errore durante la compilazione.
__________________
Uilliam Scecspir ti fa un baffo? Gioffri Cioser era uno straccione? E allora blogga anche tu, in inglese come me! |
![]() |
![]() |
![]() |
#6 | |
Member
Iscritto dal: Apr 2008
Messaggi: 81
|
Quote:
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) |
|
![]() |
![]() |
![]() |
#7 |
Senior Member
Iscritto dal: Nov 2004
Città: Tra Verona e Mantova
Messaggi: 4553
|
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'è?
__________________
Uilliam Scecspir ti fa un baffo? Gioffri Cioser era uno straccione? E allora blogga anche tu, in inglese come me! |
![]() |
![]() |
![]() |
#8 | |
Member
Iscritto dal: Apr 2008
Messaggi: 81
|
Quote:
"Il file XML specificato apparentemente non ha un foglio di stile associato. L'albero del documento è mostrato di seguito." e poi giù c'è questo: Codice:
− <!-- 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> |
|
![]() |
![]() |
![]() |
#10 |
Member
Iscritto dal: Apr 2008
Messaggi: 81
|
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 |
![]() |
![]() |
![]() |
#11 |
Senior Member
Iscritto dal: Nov 2004
Città: Tra Verona e Mantova
Messaggi: 4553
|
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.
__________________
Uilliam Scecspir ti fa un baffo? Gioffri Cioser era uno straccione? E allora blogga anche tu, in inglese come me! |
![]() |
![]() |
![]() |
#12 |
Member
Iscritto dal: Apr 2008
Messaggi: 81
|
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... |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 15:46.