开发者

Does there exist a tool for combining java files

I am joining a competition that requires me to put all my java 开发者_如何学JAVAclasses in one single .java file. Does there exist a tool that does this for me (including changing the visibility of classes to be able to do this)?

Addition: thanks for trying to help me to read the site of the competition but I quote:

It is possible to make more than one class for your program, but you will have to put the source for all classes in a single .java file (the compiler will produce multiple .class files anyway). When you do this, you should not declare your classes public, or the compiler will complain about it.

So, only 1 .java file is allowed (no jar) and in that file I can have multiple non-public classes besides my public main class (and not only static inner classes as suggested).


If you have access to Unix-y shell (for Windows, you can install e.g. Git for a decent Bash implementation, and it gives you a great VC tool):

cat *.java | sed 's/public class/class/g' >AllTehCodez.java

Doesn't have to be more complicated than that (unless you have a lot of strings containing the substring "public class", of course).

Edit: Doesn't work for package and imports. But...

(
  egrep -h ^package *.java | head -1
  egrep -h ^import *.java | sort -u
  egrep -hv '^(import|package)' *.java | sed 's/public class/class/g' 
) >AllTehCodez.java

This does of course assume all the classes are in the same package.


If we exclude various "bijou scripting haquettes" along the lines suggested above, I seriously doubt that any serious tool exists for doing this.

Why? Because this kind of nonsense goes against all known Java style rules and conventions!

The people behind that website need to be taught about archive file formats; e.g. TAR, ZIP, JAR.

EDIT

I take that back. They DO understand JAR files. Quoting from one of their documents:

Using your own executable Java jar with Caia

You can also use your own Java jar in Caia competitions. We have written the jarwrapper for that. The source of jarwrapper.c is put in the caia_install_/jarwrapper/ folder. In the Windows distro this is put into the src/ folder.

Suppose the name of your class file is JavaPlayer.class. The only thing you will have to do is to rename the executable in the bin/ folder from jarwrapper to JavaPlayer. The executable now will perform the command: java -jar JavaPlayer. The jar file should contain a manifest which points to the class with the main method.

In manager.txt you can use the program name JavaPlayer which refers to the executable that starts your Java jar player.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜