zoukankan      html  css  js  c++  java
  • 【ubuntu】发布运行java项目

    由于项目需要,使用java的socket连接硬件设备,规约是104的。这个都已经解决了。然后高高兴兴发布下,

    那么问题出现了

    问题1:怎么运行指定类中的main函数?

     现在是想运行这个MainClass里的main函数

    原因:不是类似spring boot的带有启动类,然后只是一些类而已

    解决方案:通过pom文件配置,打包指定执行的类

    直接上代码,pom的根节点中增加build节点

     build节点内容如下,指定的mainClass就是要执行的类

    <build>
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <targetPath>${basedir}/target/classes</targetPath> <!-- 可选,resource的部署目标目录 -->
                    <excludes>
                        <exclude>*.db</exclude>
                    </excludes>
                </resource>
            </resources>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.5.5</version>
                    <configuration>
                        <appendAssemblyId>false</appendAssemblyId>
                        <archive>
                            <manifest>
                                <mainClass>com.iec.main.MainClass</mainClass>
                            </manifest>
                        </archive>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                    </configuration>
                    <executions>
                        <execution>
                            <id>make-assembly</id>
                            <phase>package</phase>
                            <goals>
                                <goal>assembly</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>

    至此,直接运行java -jar xxx.jar 即可。

    细心的可以发现,其中指定了资源文件路径,

     这样项目打包后运行也可以拿到指定配置文件了

    问题2: 项目运行起来了,但是获取的系统时间差8个小时。。。

    原因: Ubuntu的配置文件中的timezone指定的默认不是cn

    解决办法: 

    先查看下现在的配置文件,只有一行

    Etc/UTC

    修改/etc/timezone,将第一行改为:

    Asia/Shanghai

    保存再次执行即可。

  • 相关阅读:
    SQL SQL 连接 JOIN 例解。(左连接,右连接,全连接,内连接,交叉连接,自连接)[转]
    ADO.NET 1.基础(SqlCommand\ExecuteScalar\ExecuteReader\sqlDataAdapter)
    SQL 14.子查询
    winform 基础
    SQL – 12.索引 + 13.join
    判断是否为数字
    SQL 17.存储过程
    SQL 16.事务
    SQL 15.变量和流程控制
    SQL 18.触发器
  • 原文地址:https://www.cnblogs.com/Rexcnblog/p/12098573.html
Copyright © 2011-2022 走看看