Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
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 998 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!
Play the free demo of Revenge of the Titans!
Offline gouessej

JGO Ninja


Medals: 33
Projects: 1


TUER


« 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

JGO Ninja


Medals: 33
Projects: 1


TUER


« 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.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (81 views)
2013-05-17 21:29:12

alaslipknot (91 views)
2013-05-16 21:24:48

gouessej (122 views)
2013-05-16 00:53:38

gouessej (114 views)
2013-05-16 00:17:58

theagentd (126 views)
2013-05-15 15:01:13

theagentd (113 views)
2013-05-15 15:00:54

StreetDoggy (158 views)
2013-05-14 15:56:26

kutucuk (180 views)
2013-05-12 17:10:36

kutucuk (180 views)
2013-05-12 15:36:09

UnluckyDevil (187 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.083 seconds with 21 queries.