Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Question about 12 years old source code

  1. #1
    Junior Member
    Join Date
    Oct 2017
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Question about 12 years old source code

    12 years ago I was working on a game with a couple of friends. Unfortunately the game wasn't finished as most of the crew members lost interest. W/e nowdays I wanted to give it a shot and try finishing it by myself. As far as I remember the game was working fine and it was connecting to the server normally, there were just some stuff that wasn't done. I have restored and compiled both the server and the client using latest Eclipse IDE + latest JDK version, however the external libraries are the still old versions (ex: log4j 1.2.13 and mysql-connector-java 5.0.8). Everything is fine I am starting the server it makes the connection to the mysql database and gets all the data it needs, but upon connecting with the client it stuck with a message "Connecting to game server". In the server I see the connection has been made, but the client stuck on that message and won't continue further as it usually must be showing me the login screen. I am wondering could the problem be in that I am using the latest Eclipse IDE and the latest JDK to build it? Looking at the fact that 12 passed and the java language has evolved in many ways and it may breaks the code somehow, however I didn't have any errors building the code with my ant build config via Eclipse. What do you guys think I should do? I was thinking on trying with older version of the IDE + older JDK (probably back from 2006).

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Question about 12 years old source code

    In the server I see the connection has been made,
    How are you trying to debug the code to see where and why it is not doing what you want?

    I use print statements that print messages to show execution progress and the value of variables that are used.

    Does the code use any Applets? I know there has been a change in how their methods work. Something to do with the code base.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Oct 2017
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Question about 12 years old source code

    I have some custom exception handlers and for anything else I am using print statements like you do. The code doesn't use any Applets.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Question about 12 years old source code

    but the client stuck
    Can you find the statement where the execution hangs by using print statements to localize the execution? For example eventually it would work down to this:
    print before 1
    statement 1
    print after 1
    If before 1 prints and after 1 does not, that points to statement 1
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Oct 2017
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Question about 12 years old source code

    I will do that, but another problem now is that for some reason I can not build a working .jar from from my ant build. I can easy Run As Java Program via Eclipse IDE, but when I build it it doesn't work. Here's how my build.xml looks like and I am using latest apache ant to compile it:
    <project name="game-server" default="build">
    	<property name="project.name" value="game-server"/>
     
    	<property environment="env" />
     
    	<property name="build.dir" value="${basedir}/build"/>
    	<property name="classes.dir" value="${build.dir}/classes"/>
     
    	<property name="src.dir" value="${basedir}/src" />
    	<property name="lib.dir" value="${basedir}/lib" />
     
    	<property name="dist.dir" value="${basedir}/dist" />
     
    	<target name="init">
    		<mkdir dir="${build.dir}" />
    		<mkdir dir="${classes.dir}" />
    		<mkdir dir="${dist.dir}" />
    	</target>
     
    	<target name="compile" depends="init">
    		<javac srcdir="${src.dir}" destdir="${classes.dir}">
    			<classpath>
    				<fileset dir="${lib.dir}">
    					<include name="*.jar" />
    				</fileset>
    			</classpath>
    		</javac>
    		<copy todir="${classes.dir}">
    			<fileset dir="${src.dir}">
    		    	<exclude name="**/*.java"/>
    		    </fileset>
    		 </copy>
    	</target>
     
    	<target name="build" depends="compile">
    		<jar basedir="${classes.dir}" destfile="${dist.dir}/${project.name}.jar">
    			<manifest>
    				<attribute name="Class-Path" value="log4j-1.2.17.jar server-core.jar" />
    				<attribute name="Main-Class" value="com.game.server.launch.LaunchServer"/>
    			</manifest>
    		</jar>
    	</target>
     
    	 <target name="clean">
    	 	<delete dir="${build.dir}"/>
        </target>
     
    </project>

    The ant compile log:

    init:
        [mkdir] Created dir: C:\Users\falsepretense\Desktop\source_last\game\game-server\build
        [mkdir] Created dir: C:\Users\falsepretense\Desktop\source_last\game\game-server\build\classes
        [mkdir] Created dir: C:\Users\falsepretense\Desktop\source_last\game\game-server\dist
     
    compile:
        [javac] C:\Users\falsepretense\Desktop\source_last\game\game-server\build.xml:21: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
        [javac] Compiling 46 source files to C:\Users\falsepretense\Desktop\game\source_last\game-server\build\classes
         [copy] Copying 1 file to C:\Users\falsepretense\Desktop\source_last\game\game-server\build\classes
     
    build:
          [jar] Building jar: C:\Users\falsepretense\Desktop\source_last\game\game-server\dist\game-server.jar
     
    BUILD SUCCESSFUL
    Total time: 1 second

    I will also list my .classpath file in case it's needed:

    <?xml version="1.0" encoding="UTF-8"?>
    <classpath>
    	<classpathentry kind="src" path="src"/>
    	<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    	<classpathentry exported="true" kind="lib" path="lib/junit.jar"/>
    	<classpathentry exported="true" kind="lib" path="lib/log4j-1.2.17.jar"/>
    	<classpathentry kind="src" path="test"/>
    	<classpathentry combineaccessrules="false" kind="src" path="/server-core"/>
    	<classpathentry kind="lib" path="lib/mysql-connector-java-8.0.15.jar"/>
    	<classpathentry kind="output" path="bin"/>
    </classpath>

    All the directories are created, the output jar is in the dist folder, but when I attempt to run it:

    Java Virtual Machine Launcher
    Error: A JNI error has occurred, please check your installation and try again
    Which upon clicking "OK" outputs:
    Java Virtual Machine Launcher
    A Java Exception has occurred.
    Trying to run via cmd (ex: java game-server.jar) and the output is:
    Error: Could not find or load main class game-server.jar
    Seem like it can't find the main class which is specified in the build.xml code showed above, so what is happening?
    Last edited by theBoolean; February 6th, 2019 at 07:06 PM.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Question about 12 years old source code

    Sorry, I don't use an IDE to build and execute my programs. I use the javac, jar and java commands.

    Trying to run via cmd (ex: java game-server.jar) and the output is:
    Error: Could not find or load main class game-server.jar
    The syntax for executing a jar file is:
    java -jar <Jarfilename>
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Oct 2017
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Question about 12 years old source code

    IDE is just for fancyness otherwise Java could be written even in a notepad and use cmd to build it. As I said I don't use the IDE to build the project, but an ant task. I guess you are familiar with the ant task structure, how does it work, etc. Personally I have never used pure javac I always depend on either ant, gradle or maven it's just easier. So based on my ant build configuration could you help me build it in something different like gradle for example or even with the command prompt (your way of doing it). Also thanks for the print technique I will use it to debug what is going on with the actual connection later on, but I have to fix the build issues first.

  8. #8
    Junior Member
    Join Date
    Oct 2017
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Question about 12 years old source code

    I have managed to fixed all the build issues and now there is another issue. Upon launching the server .jar file from CMD (ex: java -jar game-server.jar) it says error:

    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
            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)
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Unknown Source)
            at com.game.server.model.dao.MySQL.JDBCUtil.<clinit>(Unknown Source)
            at com.game.server.launch.LaunchServer.main(Unknown Source)
    Exception in thread "main" java.lang.ExceptionInInitializerError
            at com.game.server.launch.LaunchServer.main(Unknown Source)
    Caused by: java.lang.RuntimeException: Unable to load mysql driver.
            at com.game.server.model.dao.MySQL.JDBCUtil.<clinit>(Unknown Source)
            ... 1 more

    This simply means that I am missing the mysql connector/j library and I double even triple checked and the library is there included in the project and everything is fine with it. I've been searching over the web for a solution and someone in stackoverflow suggested modifying C:\xampp\mysql\bin\my.ini file disabling/commenting out skip-networking and skip-federated and enable / uncomment bind-address="127.0.0.1" . In my file skip-federated and skip-networking was disabled/commented out by default so I had to just enable/uncomment bind-address="127.0.0.1", but it still doesn't work an I doubt it's something with the xampp, but then what it could be?

    --- Update ---

    I have managed to fixed all the build issues and now there is another issue. Upon launching the server .jar file from CMD (ex: java -jar game-server.jar) it says error:

    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
            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)
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Unknown Source)
            at com.game.server.model.dao.MySQL.JDBCUtil.<clinit>(Unknown Source)
            at com.game.server.launch.LaunchServer.main(Unknown Source)
    Exception in thread "main" java.lang.ExceptionInInitializerError
            at com.game.server.launch.LaunchServer.main(Unknown Source)
    Caused by: java.lang.RuntimeException: Unable to load mysql driver.
            at com.game.server.model.dao.MySQL.JDBCUtil.<clinit>(Unknown Source)
            ... 1 more

    This simply means that I am missing the mysql connector/j library and I double even triple checked and the library is there included in the project and everything is fine with it. I've been searching over the web for a solution and someone in stackoverflow suggested modifying C:\xampp\mysql\bin\my.ini file disabling/commenting out skip-networking and skip-federated and enable / uncomment bind-address="127.0.0.1" . In my file skip-federated and skip-networking was disabled/commented out by default so I had to just enable/uncomment bind-address="127.0.0.1", but it still doesn't work an I doubt it's something with the xampp, but then what it could be?

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Question about 12 years old source code

    I guess you are familiar with the ant
    No I'm not.

    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    The jar file with that class needs to be on the classpath when the code is executed.
    One way is to add a CLASSPATH value to the manifest file.

    Can you look at the original version to see how it was configured?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Source Code
    By Alaa in forum Java Theory & Questions
    Replies: 3
    Last Post: August 3rd, 2013, 05:41 AM
  2. source code
    By bashor in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 6th, 2013, 07:33 PM
  3. Source code please
    By Gavin Fraser in forum Java Networking
    Replies: 2
    Last Post: September 17th, 2012, 03:46 PM
  4. need help with a new way of source code
    By Balger in forum Object Oriented Programming
    Replies: 15
    Last Post: August 26th, 2012, 01:41 PM