Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
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  
  server wont run?  (Read 1773 times)
0 Members and 1 Guest are viewing this topic.
Offline nethious

Senior Newbie





« Posted 2011-09-16 23:13:23 »

i need a little help, me and a friend are writing a Runescape private server, the base is almost done but for some reason the server just wont run.


im getting a run error cant find main.

code:
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  
132  
133  
134  
135  
136  
137  
138  
139  
140  
package lf;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
import lf.item.Item;
import lf.util.HostThrottle;

public class Server implements Runnable {

    public Server() {
    }
    public static final int cycleTime = 600;

    public static void main(String args[]) throws Throwable {
        if (args.length != 3) {
            System.out.println("Usage: [OnSource_password] [OnSource_port] [startup_wait]");
            return;
        }
        OnSource.init(args[0], args[1], args[2]);

        Thread t = new Thread() {

            @Override
            public void run() {

                Scanner in = new Scanner(System.in);
                while (true) {
                    try {
                        String[] args = in.nextLine().split(" ");
                        args[0] = args[0].toLowerCase();

                        if (args[0].startsWith("stop")) {
                            System.out.println("Stopping server...");
                            playerHandler.update(Integer.parseInt(args[1]));
                            Thread.sleep(Integer.parseInt(args[1]) * 1000);
                            Server.stopServer = true;
                            Server.join(250L);
                            System.out.println("Server stopped.");
                        }

                    } catch (Throwable t) {
                        t.printStackTrace();
                    }
                }
            }
        };
        t.setDaemon(true);
        t.start();

        try {
            Item.initDefs();

            clientHandler = new Server();
            (new Thread(clientHandler)).start();

            playerHandler = new PlayerHandler();

            while (!stopServer) {
                long start = System.nanoTime();
                try {
                    playerHandler.process();

                } finally {
                    long time = 600L - ((System.nanoTime() - start) / 1000000L);
                    if (time > 0L) {
                        Thread.sleep(time);
                    }
                }
            }

        } finally {
            playerHandler.destruct();
            clientHandler.destruct();
            down = true;
        }
    }
    public static boolean down;
    public static Server clientHandler;
    public static ServerSocket clientListener;
    public static boolean stopServer = false;
    public static boolean stopListener;
    public static final int GAME_PORT = 43593;
    public static PlayerHandler playerHandler;

    public static void join(long step) throws InterruptedException {
        while (!Server.down) {
            Thread.sleep(step);
        }
    }

    public void run() {
        HostThrottle ht = new HostThrottle(3);
        ServerSocket ss = null;
        try {
            try {
                ss = new ServerSocket(GAME_PORT);
                Misc.println("Game server listening on " + ss.getInetAddress().getHostAddress() + ":" + ss.getLocalPort());

                do {
                    Socket sock = ss.accept();
                    if (ht.register(sock)) {
                        sock.setTcpNoDelay(true);
                        sock.setTrafficClass(0x04 | 0x08);
                        playerHandler.newPlayer(sock);

                    } else {
                        sock.close();
                    }

                } while (!stopListener);

            } finally {
                if (ss != null) {
                    ss.close();
                }
            }

        } catch (IOException e) {
            if (!stopListener) {
                e.printStackTrace();
            } else {
                Misc.println("Game listener shut down");
            }
        }
    }

    public void destruct() {
        try {
            stopListener = true;
            if (clientListener != null) {
                clientListener.close();
            }

        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}
Offline aazimon
« Reply #1 - Posted 2011-09-17 00:03:26 »

Do you have your files in a jar? if so you need a Manifest.mf file in the meta-inf fold. The manifast file have a line with Main-Class: lf.Server
Offline nethious

Senior Newbie





« Reply #2 - Posted 2011-09-17 00:29:05 »

Do you have your files in a jar? if so you need a Manifest.mf file in the meta-inf fold. The manifast file have a line with Main-Class: lf.Server
its not built into a jar, im just running it from the source.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 342
Projects: 2
Exp: 5 years


I'm the King!


« Reply #3 - Posted 2011-09-18 03:59:58 »

How exactly do you run it? From within an IDE or from the command line?

Offline nethious

Senior Newbie





« Reply #4 - Posted 2011-09-18 20:10:58 »

How exactly do you run it? From within an IDE or from the command line?
eclipse ide
Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Reply #5 - Posted 2011-09-18 21:31:26 »

It doesn't have a regular main method. The normal one doesn't throw anything, because it's the first entrypoint. Yours throws throwable.

Offline Mike

JGO Ninja


Medals: 71
Projects: 1
Exp: 5 years


Java guru wanabee


« Reply #6 - Posted 2011-09-18 21:32:18 »

If you open the run configuration (click on the little arrow next to the run button and choose "Run Configurations" and then select the entry you are running) in Eclipse, is the "Main Class" section showing lf.Server?

Mike

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Offline ra4king

JGO Kernel


Medals: 342
Projects: 2
Exp: 5 years


I'm the King!


« Reply #7 - Posted 2011-09-19 03:43:52 »

It doesn't have a regular main method. The normal one doesn't throw anything, because it's the first entrypoint. Yours throws throwable.
It doesn't matter, the main method can throw whatever it wants.

Offline Conner_

Senior Newbie




~ Java Game Dev ~


« Reply #8 - Posted 2011-09-19 04:20:57 »

You shouldn't be throwing any exceptions in the #main() method. Nothing calls it.

Find me on GitHub: connergdavis
My current project is called Obsidian Framework and is a private Minecraft server application used to play Multiplayer.
Offline aazimon
« Reply #9 - Posted 2011-09-19 04:58:47 »

It would be best to catch the exception in the main method so you can log it for debugging.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Cypherix

Senior Newbie





« Reply #10 - Posted 2011-09-19 05:07:40 »

@Conner__ The ClassLoader calls it... herp derp

Whilst it's bad programming practices (Not only for debugging purposes) to throw an exception from the main method, it is allowed.

This however, isn't his problem. His error isn't a problem with his code, it's his IDE. This is a common error with eclipse. Because Eclipse allows you to run different projects, it requires you to manually select the project to be run. In some cases the project will have more than one main method, in which case you would need to go through the options in eclipse and select the main class that is the "real" main class.

If the problem is fixed then just back up your code and create another project.. It will usually just be a bug with the project.
Offline ra4king

JGO Kernel


Medals: 342
Projects: 2
Exp: 5 years


I'm the King!


« Reply #11 - Posted 2011-09-19 06:04:02 »

Usually hitting the "Run" button while focused on the class that has the main method or is associated with another class that has the main method works fine for me.

Offline sproingie

JGO Kernel


Medals: 202



« Reply #12 - Posted 2011-09-19 18:29:34 »

A GUI app should probably catch every exception and log it or present it to the user somehow.  But if you know you'll have a console up anyway (which you will have in your IDE), there's nothing wrong with letting exceptions propagate out of main, since the default behavior of printing the stack trace is probably what you want anyway.

Chalk up another reason why I like IDEA: Shift-Ctrl-F10 figures out what the proper run configuration is for the current window, and only ever runs that, not something you set up days or months ago.  Hitting it where there's a main method runs the app, hitting it in a test runs the test, hitting it in some random text file does nothing at all.

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.

CogWheelz (12 views)
2014-08-01 22:53:16

CogWheelz (14 views)
2014-08-01 22:51:43

CopyableCougar4 (15 views)
2014-08-01 19:37:19

CogWheelz (19 views)
2014-07-30 21:08:39

Riven (27 views)
2014-07-29 18:09:19

Riven (16 views)
2014-07-29 18:08:52

Dwinin (14 views)
2014-07-29 10:59:34

E.R. Fleming (35 views)
2014-07-29 03:07:13

E.R. Fleming (13 views)
2014-07-29 03:06:25

pw (44 views)
2014-07-24 01:59:36
Resources for WIP games
by CogWheelz
2014-08-01 18:20:17

Resources for WIP games
by CogWheelz
2014-08-01 18:19:50

List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

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
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!