- 先下载 tiny radius 源文件
- 打开 eclipse , 导入 现有的maven project
- 修改 project—> property—> java build path —> libraries 与本机安装的jdk版本一致
- 修改 pom.xml , 使其内容为 : (build部分需特别注意)
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 |
<?xml version="1.0"?> <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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.tinyradius</groupId> <artifactId>tinyradius</artifactId> <name>TinyRadius Java Radius Library</name> <version>0.9.9</version> <url>http://sourceforge.net/projects/tinyradius</url> <developers> <developer> <id>wuttke</id> <name>Matthias Wuttke</name> <email>mw@teuto.net</email> <timezone>CEST</timezone> </developer> </developers> <dependencies> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> </dependencies> <build> <resources> <resource> <targetPath>org\tinyradius\dictionary</targetPath> <filtering>false</filtering> <directory>${basedir}/src/org/tinyradius/dictionary</directory> <includes> <include>default_dictionary</include> </includes> </resource> </resources> <defaultGoal>install</defaultGoal> <sourceDirectory>src</sourceDirectory> <plugins> <plugin> <!-- Build an executable JAR --> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>org.tinyradius.test.TestServer</mainClass> </manifest> <manifestEntries> <Class-Path>.</Class-Path> </manifestEntries> </archive> </configuration> </plugin> </plugins> </build> </project> |
- maven —> run as install
- 编译完copy到centos 6 机器
- 在 centos 机器目录下新建 lib 目录 copy : common-logging 1.1.1 和 log4j 1.2.17 去 lib 目录内
- 执行
1java -jar tinyradius-0.9.9.jar
如遇报错 :
1no main manifest attribute, in tinyradius-0.9.9.jar原因是maven自动生成的 MANIFEST.MF 没有 main class 信息google后,有的答案说: 应该在 pom.xml 加这段
1234567891011121314151617<build><sourceDirectory>src</sourceDirectory><plugins><plugin><!-- Build an executable JAR --><groupId>org.tinyradius</groupId><artifactId>tinyradius</artifactId><configuration><archive><manifest><mainClass>org.tinyradius.test.TestServer</mainClass></manifest></archive></configuration></plugin></plugins></build>但是试过后还是报同样的错误 , 继续Google, 发现可以用jar 命令加额外的 manifest 内容到maven自动生成的 jar文件里面去。
方法是:
a) 新建文本文件 manifest.txt , 内容写:
1 |
Main-Class: org.tinyradius.test.TestServer |
b) 然后运行
1 |
jar umf manifest.txt tinyradius-0.9.9.jar |
‘u’ mean update , in this case , do not use ‘c’
- 至此 , main class 信息终于加到了 MANIFEST.MF 文件
- 附录 :
a) in centos , check file which name include “META” in jar :
1 |
unzip -l tinyradius-0.9.9.jar |grep META |
b) how to unzip .jar file : use 7z upzip
how to recombine extractd files back to .jar file :
1 |
jar cfv tinyradius-0.9.9.jar META-INF org |
in this case , folder as such condition