这是代码:
package mscontroller;
import javax.swing.*;
import com.apple.eawt.Application;
public class Main {
public static void main(String[] args)
{
Application app = new Application();
app.setEnabledAboutMenu(true);
AMEListener listener = new AMEListener();
app.addApplicationListener(listener);
JFrame mainFrame = new JFrame("Application Menu Example");
mainFrame.setSize(500, 500);
mainFrame.setVisible(true);
}
}
Run Code Online (Sandbox Code Playgroud)
这是错误:
Exception in thread "main" java.lang.Error: Unresolved compilation
problems: Access restriction: The type 'Application' is not API
(restriction on required library
'/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar')
Access restriction: The constructor 'Application()' is not API
(restriction on required library
'/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar')
Access restriction: The type …
Run Code Online (Sandbox Code Playgroud) 如果你有一个名为jar文件myJar.jar
位于/ MyFolder中,你要使用称为类myClass
的话,你怎么去了解通过命令行做什么呢?
我以为会进入目录然后说java -cp myJar.jar.myClass
但是没有用.任何帮助,将不胜感激.
我知道Android库项目,它允许您创建一个可以根据需要拉入Android应用程序的共享源项目.但是,这需要源可用.
我正在寻找一种方法来构建和分发可以在其他Android项目(如传统JAR)中使用的闭源库.这将需要使用Android编译器,因此它不是vanilla-Java JAR文件.FWIW,我不需要在JAR中嵌入资源/布局.
我见过http://andparcel.com/但感觉就像是一种解决方法,我宁愿使用谷歌"正式支持"的东西.另外,我需要确保我构建的JAR与Android SDK的新旧版本兼容(即我需要一种设置目标平台版本的方法等).
最新的Android工具集是否允许创建/使用JAR二进制文件?你能指出一些关于我如何做到这一点的文件吗?
我想在Android Studio中为我的库创建一个aar文件,我会选择jar选项,但我的库有资源.
知道如何从库中创建aar文件吗?
我正在尝试在我们的超级pom中定义一个属性,它将被所有子项目用作生成的工件的目标.
为此,我考虑使用project/build/finalName但这似乎不起作用,即使对于简单的poms:
命令
mvn archetype:create \
-DarchetypeGroupId=org.apache.maven.archetypes \
-DgroupId=com.mycompany.app \
-DartifactId=my-app
Run Code Online (Sandbox Code Playgroud)
POM
<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>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>my-app</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<finalName>${project.name}-testing</finalName>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
$ mvn install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building my-app
[INFO] task-segment: [install]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /tmp/mvn_test/my-app/src/main/resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Nothing …
Run Code Online (Sandbox Code Playgroud) 当我运行我时,我得到以下异常mvn install
.我甚至删除了本地存储库并再次运行获得相同的异常.
[错误]无法执行目标org.apache.maven.plugins:maven-shade-plugin:2.1:项目核心上的阴影(默认) - 批处理:创建阴影jar时出错:无效的LOC标题(错误签名) - > [帮助1 ]
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>commons-logging:commons-logging:jar:*</exclude>
</excludes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<!-- workaround for a spring issues -->
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<!-- don't want to pick up any other log4j.xml -->
<exclude>log4j.xml</exclude>
</excludes>
</filter>
</filters>
<!-- May be needed to work around another issue in Spring -->
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> …
Run Code Online (Sandbox Code Playgroud) public class PropHolder {
public static Properties prop;
static {
//code for loading properties from file
}
}
// Referencing the class somewhere else:
Properties prop = PropHolder.prop;
Run Code Online (Sandbox Code Playgroud)
class PropHolder
是我自己的一类.该类驻留在主类的同一JAR文件中.所以这不应该因为类路径中缺少任何JAR.
当我查看JAR文件时jar tf myjarfile
,我可以看到PropHolder.class
列出的那个.
顺便说一句:代码在我的本地机器上正常运行.但是当我将一些脚本部署到Linux服务器上时,它无法工作.所以我认为这不是代码的问题.但出于某种原因.部署过程很难跟踪.
可能是什么问题呢?
我有一个包含4个类的JAR,每个类都有Main方法.我希望能够根据需要运行其中的每一个.我试图从Linux机器上的命令行运行它.
E.g. The name of my JAR is MyJar.jar
Run Code Online (Sandbox Code Playgroud)
它具有主类的目录结构,如下所示:
com/mycomp/myproj/dir1/MainClass1.class
com/mycomp/myproj/dir2/MainClass2.class
com/mycomp/myproj/dir3/MainClass3.class
com/mycomp/myproj/dir4/MainClass4.class
Run Code Online (Sandbox Code Playgroud)
我知道我可以在我的Manifest文件中指定一个类作为main.但有没有什么方法可以在命令行上指定一些参数来运行我希望运行的任何类?
我试过这个:
jar cfe MyJar.jar com.mycomp.myproj.dir2.MainClass2 com/mycomp/myproj/dir2/MainClass2.class /home/myhome/datasource.properties /home/myhome/input.txt
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误:
com/mycomp/myproj/dir2/MainClass2.class : no such file or directory
Run Code Online (Sandbox Code Playgroud)
(在上面的命令中,'/ home/myhome/datasource.properties'和'/home/myhome/input.txt'是命令行参数).
我现在不在IDE的前面,只是查看API规范.
CodeSource src = MyClass.class.getProtectionDomain().getCodeSource();
if (src != null) {
URL jar = src.getLocation();
}
Run Code Online (Sandbox Code Playgroud)
我想确定一个类来自哪个JAR文件.这是这样做的吗?
jar ×10
java ×8
android ×2
aar ×1
class ×1
classloader ×1
command-line ×1
decompiling ×1
deployment ×1
eclipse ×1
java-ee ×1
java-me ×1
macos ×1
maven ×1
maven-2 ×1
runtime ×1