简体   繁体   English

如何在 Windows 10 上安装 javalin

[英]How to install javalin on windows 10

The instruction on the javalin website are not clear to me. javalin 网站上的说明我不清楚。 Maybe I'm just slow but, it seems that I'm missing a couple of parts to the puzzle that the website doesn't make obvious.也许我只是很慢,但是,似乎我遗漏了网站没有明确说明的难题的几个部分。 For example, to install flask once you have python installed all you do is type "pip install flask" in the command line and thats it.例如,一旦你安装了 python 就安装flask,你要做的就是在命令行中输入“pip install flask”,就是这样。 If you don't have pip then install pip then flask as above.如果你没有 pip 然后安装 pip 然后按上面的方法安装flask。 pretty strait forward stuff.相当狭窄的东西。

For javalin it says just add the dependencies code to maven.对于 javalin,它说只需将依赖项代码添加到 maven。 Sooo, I guess I have to download maven? Sooo,我想我必须下载maven? There are instruction for eclipse and intellij so, does that mean that maven is bundled with those 2 IDEs?有eclipse和intellij的说明,这是否意味着maven与这两个IDE捆绑在一起? What if I want to use visual studio code?如果我想使用 Visual Studio 代码怎么办? Do I really have to download another IDE?我真的需要下载另一个 IDE 吗? Anyways, if I download and install maven then are there additional files to download?无论如何,如果我下载并安装maven,那么还有其他文件要下载吗? You would think you need the javalin related files.您会认为您需要 javalin 相关文件。 There is also a zip file but where do I put it?还有一个zip文件,但我把它放在哪里? where the sun don't shine?哪里没有阳光? I think this is one of those things were if you are accustomed to this side of development then its pretty strait forward but for newbies and hobbyist not so much.我认为这是其中之一,如果你习惯了这一方面的发展,那么它就相当困难,但对于新手和业余爱好者来说就不是那么回事了。

Long story short can someone give me some step by steps?长话短说有人可以给我一些步骤吗?

There are various ways to start using Javalin - here is one (it's the way I started - and yes, it was on Windows 10).有多种方法可以开始使用 Javalin - 这里是一种(这是我开始的方式 - 是的,它是在 Windows 10 上)。

I happen to use Apache NetBeans (v 11.1 currently) as my Java IDE most of the time, but it's a similar process with Eclipse (and others, I'm sure).大多数时候,我碰巧使用Apache NetBeans (当前为 v 11.1)作为我的 Java IDE,但它与 Eclipse(以及其他人,我敢肯定)的过程类似。 It also helps if you have some experience with Maven - but Maven is built into NetBeans (and Eclipse), so you don't have to download Maven separately to get started.如果您对 Maven 有一些经验,它也会有所帮助 - 但 Maven 内置于 NetBeans(和 Eclipse)中,因此您无需单独下载 Maven 即可开始使用。

Assuming NetBeans (and a reasonably recent version of Java - I am using 11):假设 NetBeans(以及最近版本的 Java - 我使用的是 11):

In NetBeans:在 NetBeans 中:

1) Select File > New Project. 1) 选择文件 > 新建项目。

2) For "Categories" choose "Java with Maven". 2) 对于“类别”,选择“Java with Maven”。

3) For "Projects" choose Java Application". 3) 对于“项目”,选择“Java 应用程序”。

4) Click on "Next". 4) 点击“下一步”。

5) For "Project Name", choose whatever name you like (or leave the default name, which will be "mavenproject1" or something like that). 5) 对于“项目名称”,选择您喜欢的任何名称(或保留默认名称,即“mavenproject1”或类似名称)。

6) For "Group ID" I tend to use "org.me" - whatever you want. 6) 对于“组 ID”,我倾向于使用“org.me”——无论你想要什么。

7) Click on "Finish". 7) 点击“完成”。

8) In the newly created project (left hand side of the IDE in the "Projects" tab), open the "Project Files" folder. 8) 在新创建的项目中(IDE 左侧的“项目”选项卡),打开“项目文件”文件夹。 There will be a new "pom.xml" file in there.那里会有一个新的“pom.xml”文件。

9) Double-click on the file to open it. 9) 双击文件将其打开。 This is where you "just add that Maven dependency" that the Javalin site mentions.这是 Javalin 站点提到的“只需添加该 Maven 依赖项”的地方。 It needs to be added to a new <dependencies> section.它需要添加到新的<dependencies>部分。

You will also need to ADD THE SLF4J dependencies - see the example below - to support logging.您还需要添加 SLF4J依赖项 - 请参见下面的示例 - 以支持日志记录。

Here is a typical new POM file at this stage:这是现阶段典型的新 POM 文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.me</groupId>
    <artifactId>mavenproject1</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>

    <dependencies>

        <dependency>
            <groupId>io.javalin</groupId>
            <artifactId>javalin</artifactId>
            <version>3.7.0</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.8.0-beta4</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.28</version>
        </dependency>

    </dependencies>

</project>

10) Choose Run > Build Project. 10) 选择运行 > 构建项目。 You haven't written any code yet, but this will cause Maven to download the Javalin JAR file - and all its dependent JARs.您还没有编写任何代码,但这将导致 Maven 下载 Javalin JAR 文件 - 及其所有依赖的 JAR。 You can see them all in your project's "Dependencies" folder.您可以在项目的“Dependencies”文件夹中看到它们。

There are more than 20 JARs downloaded.下载了 20 多个 JAR。 For example, a bunch of Jetty JARs - because Javalin uses an embedded Jetty web server behind the scenes.例如,一堆 Jetty JAR - 因为 Javalin 在幕后使用嵌入式 Jetty Web 服务器。

11) Create a new Java class called "HelloWorld". 11) 创建一个名为“HelloWorld”的新 Java 类。

12) You can paste in the hello world example from the Javalin web site: 12) 您可以粘贴来自 Javalin 网站的hello world 示例

import io.javalin.Javalin;

public class HelloWorld {
    public static void main(String[] args) {
        Javalin app = Javalin.create().start(7000);
        app.get("/", ctx -> ctx.result("Hello World"));
    }
}

13) Run the project in NetBeans (or your IDE of choice). 13) 在 NetBeans(或您选择的 IDE)中运行项目。 You should see the following terminal output - or similar:您应该看到以下终端输出 - 或类似的:

[main] INFO io.javalin.Javalin - 
           __                      __ _
          / /____ _ _   __ ____ _ / /(_)____
     __  / // __ `/| | / // __ `// // // __ \
    / /_/ // /_/ / | |/ // /_/ // // // / / /
    \____/ \__,_/  |___/ \__,_//_//_//_/ /_/

        https://javalin.io/documentation

[main] INFO org.eclipse.jetty.util.log - Logging initialized @208ms to org.eclipse.jetty.util.log.Slf4jLog
[main] INFO io.javalin.Javalin - Starting Javalin ...
[main] INFO io.javalin.Javalin - Listening on http://localhost:7000/
[main] INFO io.javalin.Javalin - Javalin started in 311ms \o/

14) Open a browser and browse to http://localhost:7000/ - you should see your "hello world" message. 14) 打开浏览器并浏览到http://localhost:7000/ - 您应该会看到“hello world”消息。

(If port 7000 is already in use, then edit your source code to choose a different port.) (如果端口 7000 已在使用中,则编辑源代码以选择不同的端口。)

That really is the barest-bones way to get started.这确实是最简单的入门方式。

I see that the question was down-voted - probably because it's really more of a Maven question than a Javalin question, at heart.我看到这个问题被否决了 - 可能是因为它本质上更像是一个 Maven 问题而不是一个 Javalin 问题。

But I hope this helps.但我希望这会有所帮助。 I have enjoyed using Javalin - hope you do too.我很喜欢使用 Javalin - 希望你也喜欢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM