Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Help ANT and LWJGL !  (Read 1508 times)
0 Members and 1 Guest are viewing this topic.
Offline beaucoralk

Senior Newbie





« Posted 2012-02-01 11:53:26 »

Hi all,

I would like to use 'Ant' to compile and create the '.jar' of my project.
But I can not properly integrate the LWJGL library, I wonder what I should put in the 'Ant task' which I use at compile time, the launch and creation of the executable file ('.jar').

The three 'Ant task':
Compilation:
1  
2  
3  
4  
5  
6  
7  
8  
9  
<target name="compile" depends="init"
      description=" : compilation des programmes sous le repertoire sources">
      <mkdir dir="${pathClass}"/>
      <javac srcdir="${pathSrc}" destdir="${pathClass}" source="${source}"
        debug="on" debuglevel="lines,vars,source"
        compiler="${compiler}" includeantruntime="false">
        <classpath refid="projectClasspath"/>
      </javac>
</target>


Running:
1  
2  
3  
4  
5  
6  
7  
8  
<target name="run" depends="compile"
      description=" : execution de la classe principale de l application">
      <java classname="${MainClass}" classpath="${pathClass}" fork="true">
        <assertions>
            <enable/>
        </assertions>
      </java>
</target>


Creat .jar:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
<target name="build" depends="compile"
      description=" : construction d une application double-clickable">
      <jar destfile="${pathBuild}/${JarFile}" index="true">
            <manifest>
                <attribute name="Main-Class" value="${MainClass}" />
                <attribute name="Built-By"   value="${user.name}"/>
            </manifest>
            <fileset dir="${pathClass}"/>
            <fileset dir="${basedir}">
                <include name="${dirRes}/"/>
            </fileset>
      </jar>
</target>


How do I do to integrate the library in my project?
Offline tom
« Reply #1 - Posted 2012-02-01 16:42:12 »

1) You need to include the lwjgl jars in the "projectClasspath":
<path id="projectClasspath">
            <pathelement location="path/to/lwjgl.jar"/>
</path>
2) You need to add -Djava.library.path to point to the lwjgl native files in the run task:
<java....>
...
<jvmarg value="-Djava.library.path=./lib"/>
</java>

Offline beaucoralk

Senior Newbie





« Reply #2 - Posted 2012-02-01 17:02:27 »

I've this error :

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
     [java] Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException
     [java]    at net.battlesquare.src.Battlesquare.<init>(Battlesquare.java:16)
     [java]    at net.battlesquare.src.BattlesquareImpl.<init>(BattlesquareImpl.java:14)
     [java]    at net.battlesquare.client.BattlesquareClient.main(BattlesquareClient.java:21)
     [java] Caused by: java.lang.ClassNotFoundException: org.lwjgl.LWJGLException
     [java]    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
     [java]    at java.security.AccessController.doPrivileged(Native Method)
     [java]    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
     [java]    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
     [java]    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
     [java]    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
     [java]    ... 3 more
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gouessej
« Reply #3 - Posted 2012-02-02 19:24:46 »

tom is right. Your run task must set both the Java library path and the class path. If you want, I can show you an example of script doing the same thing, I just need to adapt it for LWJGL. In mine, I use several tasks to create the JAR, sign all JARs, create the JNLP file, run the game, etc...

You need to use some conditions to build the Java library path correctly whatever the OS and the architecture. I did it and it works fine Smiley

Offline beaucoralk

Senior Newbie





« Reply #4 - Posted 2012-02-02 20:02:19 »

I fixed the bug for the Compile and Run Ant Task.... but... don't for the Creat .jar task...

My build.xml :
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
<?xml version="1.0" encoding="utf-8"?>
<project name="..." default="but">
  <target name="init" depends="initprojet,initPerso,initstructure,initClasspath"/>

  <target name="but"
      description=" : cible par defaut" depends="run"/>

  <target name="initprojet"
         description=" : initialisation des proprietes du projet">
   <property name="MainClass"      value="MainClass"/>
   <property name="TestClass"      value="TestClass"/>
   <property name="build.compiler" value="javac1.5"/>
   <property name="JarFile"        value="JarFile.jar"/>
    <property name="charset"        value="utf8"/>
   <property name="compiler"       value="javac1.6"/>
   <property name="source"         value="1.6"/>
    <!-- You OS : macosx, linux, windows -->
    <property name="os"             value="macosx"/>
  </target>
 
  <target name="initPerso"
         description=" : initialisation des chemins sur son ordinateur">
    <property name="pathAPI"       value="file:///Ressources/javadoc/api"/>
  </target>
 
  <target name="initstructure"
         description=" : initialisation des proprietes liees a la stucture">
      <property name="dirRes"     value="ress"/>
      <property name="dirClass"   value="class"/>
      <property name="dirDocs"    value="doc"/>
      <property name="dirSource"  value="src"/>
      <property name="dirBuild"   value="build"/>
      <property name="dirLib"     value="lib"/>

      <property name="pathSrc"    value="${basedir}/${dirSource}"/>
      <property name="pathClass"  value="${basedir}/${dirClass}"/>
      <property name="pathDocs"   value="${basedir}/${dirBuild}/${dirDocs}"/>
      <property name="pathRes"    value="${basedir}/${dirRes}"/>
      <property name="pathBuild"  value="${basedir}/${dirBuild}"/>
      <property name="pathLib"    value="${basedir}/${dirLib}"/>
     
     <mkdir dir="${pathClass}"/>
  </target>
 
  <target name="initClasspath"
      description=" : initialisation des chemins d'acces aux classes">
     <path id="projectClasspath">
      <pathelement path="${pathClass}/"/>
      <pathelement path="${pathLib}/junit/junit-4.8.2.jar"/>
      <pathelement path="${pathLib}/lwjgl/lwjgl.jar"/>
      <pathelement path="${pathLib}/lwjgl/lwjgl_util.jar"/>
     </path>
      <property name="pathNativeLwjgl" value="${pathLib}/lwjgl/${os}" />
  </target>

   <target name="compile" depends="init"
      description=" : compilation des programmes sous le repertoire sources">
      <mkdir dir="${pathClass}"/>
      <javac srcdir="${pathSrc}" destdir="${pathClass}" source="${source}"
        debug="on" debuglevel="lines,vars,source"
        compiler="${compiler}" includeantruntime="false">
        <classpath refid="projectClasspath"/>
      </javac>
      <!-- For uzip all library in the class path
      <unzip dest="${pathClass}">
        <fileset dir="${pathLib}">
        </fileset>
      </unzip>
      -->
   </target>
   
   <target name="tests" depends="compile"
      description=" : tests du modele">
      <java classname="${TestClass}" fork="true">
      <classpath refid="projectClasspath"/>
        <assertions>
            <enable/>
        </assertions>
      </java>
   </target>
   
   <target name="doc" depends="compile"
      description=" : documentation des programmes sous le repertoire sources">
      <mkdir dir="${pathDocs}"/>
      <javadoc destdir="${pathDocs}" Author="true" Version="true" Private="true"
         encoding="${charset}" charset="${charset}" docencoding="${charset}">
         <fileset dir="${pathSrc}"/>
         <classpath refid="projectClasspath"/>
         <link href="${pathAPI}"/>
      </javadoc>
   </target>
     
   <target name="run" depends="compile"
      description=" : execution de la classe principale de l application">
      <java classname="${MainClass}" fork="true">
      <classpath refid="projectClasspath"/>
        <assertions>
            <enable/>
        </assertions>
      <jvmarg value="-Djava.library.path=${pathNativeLwjgl}"/>
      </java>
   </target>
   
   <target name="build" depends="compile"
      description=" : construction d une application double-clickable">
      <jar destfile="${pathBuild}/${JarFile}" index="true">
            <manifest>
                <attribute name="Main-Class" value="${MainClass}" />
                <attribute name="Built-By"   value="${user.name}" />
            </manifest>
            <fileset dir="${pathClass}"/>
            <fileset dir="${basedir}">
                <include name="${dirRes}/"/>
                <include name="${dirLib}/"/>
            </fileset>
      </jar>
   </target>
   
   <target name="clean" depends="init"
    description=" : nettoyage des .class et de la documentation">
      <delete dir="${dirClass}" />
      <delete dir="${dirDocs}" />
   </target>
   
   <target name="cleanall" depends="init"
    description=" : nettoyage des .class, de la documentation et de l'application double-clickable.">
      <delete dir="${dirClass}" />
      <delete dir="${dirDocs}" />
        <delete dir="${dirBuild}" />
   </target>
</project>


How can I do for the simple double click the jar file can be run taking into account the '-Djava.library.path = $ {pathNativeLwjgl}'?
Offline gouessej
« Reply #5 - Posted 2012-02-02 23:33:45 »

Using a single JAR file is a bad idea because double clicking on it rarely run the application because of WinRAR, Ark, etc... Do as you wish but applets and Java Web Start are more reliable. Maybe you can set the Java library path in the manifest.

Offline beaucoralk

Senior Newbie





« Reply #6 - Posted 2012-02-03 06:11:52 »

I had just the idea of ​​creating a 'jar' which is one of my application launcher and launch just the 'jar' that needs libraries that seems a good idea right?
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (35 views)
2014-07-24 01:59:36

Riven (36 views)
2014-07-23 21:16:32

Riven (23 views)
2014-07-23 21:07:15

Riven (26 views)
2014-07-23 20:56:16

ctomni231 (56 views)
2014-07-18 06:55:21

Zero Volt (48 views)
2014-07-17 23:47:54

danieldean (39 views)
2014-07-17 23:41:23

MustardPeter (43 views)
2014-07-16 23:30:00

Cero (59 views)
2014-07-16 00:42:17

Riven (56 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!