Webserver with php embedded into bukkit plugin?

Discussion in 'Plugin Development' started by MCMatters, Jul 29, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    MCMatters

    How can I have a bukkit plugin that includes a webserver with php installed? I don't want to have people that install my plugin have to install xampp servers and I need php for a login script. Dynmap maybe uses a java webserver with php and maybe Chiller 's admin panel
     
  2. Offline

    Chiller

    MCMatters We actually don't use PHP, we use another server side language called JSP, similar to PHP but its in java instead.

    Just lookup embedded jetty in java. That is what both dynmap and my admin panel use.
     
  3. Offline

    MCMatters

    Chiller would u be able to add me on Skype (mcmatters123) and show me how?
     
  4. Offline

    Chiller

    MCMatters Well first off do you have maven installed?
     
  5. Offline

    MCMatters

    Chiller yes

    Chiller I got maven for eclipse

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  6. Offline

    Chiller

    So then add all these dependencies:

    And also make sure your packaged jar is shaded with all these dependencies.

    Code:java
    1. <dependency>
    2. <groupId>javax.servlet</groupId>
    3. <artifactId>javax.servlet-api</artifactId>
    4. <version>3.1.0</version>
    5. </dependency>
    6. <dependency>
    7. <groupId>org.eclipse.jetty</groupId>
    8. <artifactId>jetty-annotations</artifactId>
    9. <version>9.2.1.v20140609</version>
    10. </dependency>
    11. <dependency>
    12. <groupId>org.eclipse.jetty</groupId>
    13. <artifactId>jetty-webapp</artifactId>
    14. <version>9.2.1.v20140609</version>
    15. </dependency>
    16. <dependency>
    17. <groupId>org.eclipse.jetty</groupId>
    18. <artifactId>apache-jsp</artifactId>
    19. <version>9.2.1.v20140609</version>
    20. <type>jar</type>
    21. </dependency>
    22. <dependency>
    23. <groupId>org.eclipse.jetty</groupId>
    24. <artifactId>apache-jstl</artifactId>
    25. <version>9.2.1.v20140609</version>
    26. <type>pom</type>
    27. </dependency>


    And then add this to your onEnable and make sure to shutdown the server in onDisable!

    Code:java
    1. Server server = new Server(port);
    2.  
    3. System.setProperty("org.apache.jasper.compiler.disablejsr199", "false");
    4.  
    5. WebAppContext context = new WebAppContext();
    6.  
    7. context.setContextPath("/");
    8. context.setResourceBase(new File(getDataFolder(), "webroot").toURI().toASCIIString());
    9. context.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
    10.  
    11. server.setHandler(context);
    12.  
    13. JettyJasperInitializer sci = new JettyJasperInitializer();
    14. ServletContainerInitializersStarter sciStarter = new ServletContainerInitializersStarter(context);
    15.  
    16. ContainerInitializer initializer = new ContainerInitializer(sci, null);
    17. List<ContainerInitializer> initializers = new ArrayList<ContainerInitializer>();
    18.  
    19. initializers.add(initializer);
    20.  
    21. context.setAttribute("org.eclipse.jetty.containerInitializers", initializers);
    22. context.addBean(sciStarter, true);
    23.  
    24. ClassLoader jspClassLoader = new URLClassLoader(new URL[0], this.getClass().getClassLoader());
    25. context.setClassLoader(jspClassLoader);
    26.  
    27. ServletHolder holderJsp = new ServletHolder("jsp", JspServlet.class);
    28.  
    29. holderJsp.setInitOrder(0);
    30. holderJsp.setInitParameter("fork", "false");
    31. holderJsp.setInitParameter("xpoweredBy", "false");
    32. holderJsp.setInitParameter("keepgenerated", "false");
    33. holderJsp.setInitParameter("compilerTargetVM", "1.7");
    34. holderJsp.setInitParameter("compilerSourceVM", "1.7");
    35. holderJsp.setInitParameter("logVerbosityLevel", "DEBUG");
    36.  
    37. context.addServlet(holderJsp, "/index.jsp");
    38.  
    39. server.start();
     
  7. Offline

    MCMatters

    And how do I add files to the webserver and how do I code it and can HTML be used in jsp files
     
  8. Offline

    Chiller

    MCMatters

    Right now the code I gave you will check for the index.jsp file in your plugins folder/webroot/index.jsp
     
  9. Offline

    MCMatters

    Chiller how do i stop the server
     
  10. Offline

    Chiller

  11. Offline

    MCMatters

    so i put it on my server and started it
     
  12. Offline

    Chiller

  13. Offline

    MCMatters

    what is it supposed to do
     
  14. Offline

    Chiller

    MCMatters Well in your plugin folder add another named webroot and add a file called index.jsp and put a simple Hello World in there and then navigate to localhost:port/index.jsp
     
  15. Offline

    MCMatters

    first i got a plugin.yml error, i fixed that then i got:
    [18:08:22] [Server thread/ERROR]: Could not load 'plugins\test.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.NoClassDefFoundError: org/eclipse/jetty/server/Handler

    pom.xml
    Code:java
    1. project xmlns="[URL]http://maven.apache.org/POM/4.0.0[/URL]" xmlns:xsi="[URL]http://www.w3.org/2001/XMLSchema-instance[/URL]" xsi:schemaLocation="[URL]http://maven.apache.org/POM/4.0.0[/URL] [URL]http://maven.apache.org/xsd/maven-4.0.0.xsd[/URL]">
    2. <modelVersion>4.0.0</modelVersion>
    3. <groupId>me.dillan</groupId>
    4. <artifactId>test</artifactId>
    5. <version>0.0.1-SNAPSHOT</version>
    6. <dependencies>
    7. <dependency>
    8. <groupId>javax.servlet</groupId>
    9. <artifactId>javax.servlet-api</artifactId>
    10. <version>3.1.0</version>
    11. </dependency>
    12. <dependency>
    13. <groupId>org.eclipse.jetty</groupId>
    14. <artifactId>jetty-annotations</artifactId>
    15. <version>9.2.1.v20140609</version>
    16. </dependency>
    17. <dependency>
    18. <groupId>org.eclipse.jetty</groupId>
    19. <artifactId>jetty-webapp</artifactId>
    20. <version>9.2.1.v20140609</version>
    21. </dependency>
    22. <dependency>
    23. <groupId>org.eclipse.jetty</groupId>
    24. <artifactId>apache-jsp</artifactId>
    25. <version>9.2.1.v20140609</version>
    26. <type>jar</type>
    27. </dependency>
    28. <dependency>
    29. <groupId>org.eclipse.jetty</groupId>
    30. <artifactId>apache-jstl</artifactId>
    31. <version>9.2.1.v20140609</version>
    32. <type>pom</type>
    33. </dependency>
    34. <dependency>
    35. <groupId>org.bukkit</groupId>
    36. <artifactId>bukkit</artifactId>
    37. <version>1.7.9-R0.2</version>
    38. <type>jar</type>
    39. <scope>provided</scope>
    40. </dependency>
    41. </dependencies>
    42. <build>
    43. <plugins>
    44. <plugin>
    45. <groupId>org.apache.maven.plugins</groupId>
    46. <artifactId>maven-compiler-plugin</artifactId>
    47. <configuration>
    48. <source>1.7</source>
    49. <target>1.7</target>
    50. </configuration>
    51. </plugin>
    52. </plugins>
    53. </build>
    54. <repositories>
    55. <repository>
    56. <id>bukkit-repo</id>
    57. <url>[URL]http://repo.bukkit.org/content/groups/public/</url>[/URL]
    58. </repository>
    59. </repositories>
    60. </project>


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  16. Offline

    Traks

    The dependencies you used aren't added to your plugin's JAR, use the maven shade plugin to include them.
     
  17. Offline

    MCMatters

    is it for eclipse?
     
  18. Offline

    Garris0n

    It's for maven...
     
  19. Offline

    MCMatters

    hintss likes this.
  20. Offline

    YoshiGenius

    *le sigh*
     
  21. Offline

    MCMatters

    YoshiGenius can u help me?

    how

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  22. Offline

    Garris0n

  23. Offline

    MCMatters


    I used:
    Code:java
    1. <plugin>
    2. <groupId>org.apache.maven.plugins</groupId>
    3. <artifactId>maven-shade-plugin</artifactId>
    4. <version>1.3</version>
    5. </plugin>


    Traks Chiller

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  24. Offline

    Traks

    Did you click on the link I provided? It contains other links to a few examples...
     
  25. Offline

    MCMatters

    Traks what r the links

    Traks can u give all the examples

    Chiller Chiller Chiller Help?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  26. Offline

    Chiller

    MCMatters

    Code:java
    1. <plugin>
    2. <groupId>org.apache.maven.plugins</groupId>
    3. <artifactId>maven-shade-plugin</artifactId>
    4. <version>1.6</version>
    5. <executions>
    6. <execution>
    7. <phase>package</phase>
    8. <goals>
    9. <goal>shade</goal>
    10. </goals>
    11. </execution>
    12. </executions>
    13. <configuration>
    14. <transformers>
    15. <transformer
    16. implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
    17. </transformers>
    18.  
    19. <filters>
    20. <filter>
    21. <artifact>*:*</artifact>
    22. <excludes>
    23. <exclude>META-INF/*.SF</exclude>
    24.   <exclude>META-INF/*.DSA</exclude>
    25.   </excludes>
    26.   </filter>
    27.   </filters>
    28.   </configuration>
    29. </plugin>


    Then package up your plugin using mvn package
     
  27. Offline

    MCMatters

    Chiller i use m2e maven 2 eclipse

    Chiller
    I added that and i still got the class not found error

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  28. Offline

    Chiller

    MCMatters You know what you have to do is google how to setup maven shade
     
  29. Offline

    MCMatters

    Chiller how do u set it up tho

    How do I setup maven shade

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  30. Offline

    xTigerRebornx

    MCMatters Should learn the concept of following the rule "Bump only 24 hours" (or was it 12? can't remember. Either way, you aren't following either).
    http://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html
    Learn to use google rather then spamming posts every 30min. Link came from about 5 seconds of googling. If you are still confused, then specify what you are specifically confused about rather then constantly spamming posts about how to setup maven and maven shade and asking "what do I do".
     
Thread Status:
Not open for further replies.

Share This Page